一个 ServiceHost,两个端点(net.tcp 和基本 http)

发布于 2024-11-29 23:32:11 字数 1896 浏览 0 评论 0原文

我的 netTcp 主机正在工作;我们正在尝试添加对 Mac 的支持,因此正在添加 BasicHttpBinding。最终,我想使用相同的 ServiceHost 来执行此操作,但是当我尝试浏览到 http://localhost :8085/Lss/test (测试是我设计的一个操作合约,只是为了输出一些文本)它响应“400 Bad Request”。我缺少什么?

这是作为 Windows 服务托管的。 App.config 设置如下所示:

  <service name="Wcf.Lss" behaviorConfiguration="DefaultBehavior">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="Wcf.ILss"/>
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" contract="Wcf.ILss" />
  </service>
</services>
<bindings>
  <netTcpBinding>
    <binding name="netTcpBinding" maxReceivedMessageSize="9655360" maxBufferSize="9655360" maxBufferPoolSize="524288">
      <readerQuotas maxArrayLength = "932000" maxStringContentLength="900000" maxDepth="32"/>
      <security mode="None"></security>
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="DefaultBehavior" >
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

主机的配置方式如下:

var baseTcpUri = new Uri("net.tcp://localhost:8080/Lss");
var baseHttpUri = new Uri("http://localhost:8085/Lss");
var host = new ServiceHost(wcfSingleton, baseTcpUri, baseHttpUri);

host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true, HttpGetUrl=baseHttpUri });

var throttlingBehavior = new System.ServiceModel.Description.ServiceThrottlingBehavior();
throttlingBehavior.MaxConcurrentCalls = 50;
throttlingBehavior.MaxConcurrentInstances = 10;
throttlingBehavior.MaxConcurrentSessions = 10;
host.Description.Behaviors.Add(throttlingBehavior);

host.Open();

I've got working netTcp host working; we are trying to add support for Mac and so are adding BasicHttpBinding. Ultimately, I'd like to use the same ServiceHost to do this, but when I try to browse to http://localhost:8085/Lss/test (test is an OperationContract I've got designed just to output some text) it responds with "400 Bad Request." What am I missing?

This is hosted as a Windows Service. Here is how the App.config setup looks:

  <service name="Wcf.Lss" behaviorConfiguration="DefaultBehavior">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="Wcf.ILss"/>
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" contract="Wcf.ILss" />
  </service>
</services>
<bindings>
  <netTcpBinding>
    <binding name="netTcpBinding" maxReceivedMessageSize="9655360" maxBufferSize="9655360" maxBufferPoolSize="524288">
      <readerQuotas maxArrayLength = "932000" maxStringContentLength="900000" maxDepth="32"/>
      <security mode="None"></security>
    </binding>
  </netTcpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="DefaultBehavior" >
      <serviceDebug includeExceptionDetailInFaults="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

The host is configured this way:

var baseTcpUri = new Uri("net.tcp://localhost:8080/Lss");
var baseHttpUri = new Uri("http://localhost:8085/Lss");
var host = new ServiceHost(wcfSingleton, baseTcpUri, baseHttpUri);

host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true, HttpGetUrl=baseHttpUri });

var throttlingBehavior = new System.ServiceModel.Description.ServiceThrottlingBehavior();
throttlingBehavior.MaxConcurrentCalls = 50;
throttlingBehavior.MaxConcurrentInstances = 10;
throttlingBehavior.MaxConcurrentSessions = 10;
host.Description.Behaviors.Add(throttlingBehavior);

host.Open();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2024-12-06 23:32:11

您无法浏览到操作,只能浏览到在您的情况下托管在基地址的服务。因此,当您浏览到“http://localhost:8085/Lss”时,您应该会看到标准的 WCF 测试页面。

You can't browse to an operation, you can only browse to the service which in your case is hosted at the base address. So, when you browse to "http://localhost:8085/Lss" you should see the standard WCF test page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文