同时具有 basicHttpBinding 和 netTcpBinding 的 WCF 服务;无法访问 HTTP 端点
我想通过 netTcpBinding 和 basicHttpBinding 提供相同的接口。我还想为两个端点提供 wsdl。当我访问 http://localhost:9876/TestService/ 时,我得到了 mex 端点,其中包含位于 http://localhost:9876/TestService/?wsdl 的 Tcp 端点信息
,但是地址http://localhost:9876/TestService/ws
没有响应,我不明白为什么。我有基地址和相对地址。有人可以帮我指出缺少什么吗?现在,我只是想开始使用 TestImplementation 服务,而且我还没有搞乱 MessaginImplementation 服务。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SimpleBinding" />
</basicHttpBinding>
<netTcpBinding>
<binding name="DefaultTCPBinding" transactionFlow="true" />
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding"
httpGetBindingConfiguration="" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MetadataBehavior" name="CompanyX.AppServer.Implementation.TestImplementation">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="DefaultTCPBinding"
name="TestTCPEndpoint" contract="CompanyX.AppServer.Interfaces.ITest" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="TestMex" contract="IMetadataExchange" />
<endpoint address="/ws" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
name="Test" contract="CompanyX.AppServer.Interfaces.ITest" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9878/TestService" />
<add baseAddress="http://localhost:9876/TestService/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="MetadataBehavior" name="CompanyX.AppServer.Implementation.MessaginImplementation">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="DefaultTCPBinding"
name="MessagingTCPEndpoint" contract="CompanyX.AppServer.Interfaces.IMessaging" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="MessagingMex" contract="CompanyX.AppServer.Interfaces.IMessaging" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9878/MessagingService" />
<add baseAddress="http://localhost:9876/MessagingService" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
I want to make available the same interface with a netTcpBinding and basicHttpBinding. I also wanna make available the wsdl for both endpoints. When I access http://localhost:9876/TestService/
, I get the mex endpoint that has the information for the Tcp endoint at http://localhost:9876/TestService/?wsdl
, but the address http://localhost:9876/TestService/ws
does not respond, and I can't understand why. I have the base address, and the relative address. Can someone lend me a hand pointing out what's missing? Right now, I'm just trying to get working the TestImplementation service, and I haven't messed with the MessaginImplementation service.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SimpleBinding" />
</basicHttpBinding>
<netTcpBinding>
<binding name="DefaultTCPBinding" transactionFlow="true" />
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding"
httpGetBindingConfiguration="" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MetadataBehavior" name="CompanyX.AppServer.Implementation.TestImplementation">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="DefaultTCPBinding"
name="TestTCPEndpoint" contract="CompanyX.AppServer.Interfaces.ITest" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="TestMex" contract="IMetadataExchange" />
<endpoint address="/ws" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
name="Test" contract="CompanyX.AppServer.Interfaces.ITest" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9878/TestService" />
<add baseAddress="http://localhost:9876/TestService/" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="MetadataBehavior" name="CompanyX.AppServer.Implementation.MessaginImplementation">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="DefaultTCPBinding"
name="MessagingTCPEndpoint" contract="CompanyX.AppServer.Interfaces.IMessaging" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="MessagingMex" contract="CompanyX.AppServer.Interfaces.IMessaging" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9878/MessagingService" />
<add baseAddress="http://localhost:9876/MessagingService" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我来说这是一个菜鸟错误。这实际上是正确的。答案就在下面的帖子。
当我点击基本 HTTP 类时,我只收到浏览器的响应,但使用此 wsdl,我可以连接这两个绑定。
It's a rookie mistake on my part. It's actually correct. The answer is in the post below.
I only get a response from the browser when I hit the base HTTP class, but using this wsdl, I can connect with both bindings.
我怀疑您的服务端点地址是错误的:
因为它是相对地址(添加到您的基地址),所以它应该只是
ws
- 没有前导正斜杠:尝试不使用正斜杠!应该这样工作。
I suspect your service endpoint address is wrong:
Since it's a relative address (added to your base address), it should be just
ws
- no leading forward slash:Try it without the forward slash! Should work that way.