【问题标题】:WCF service with both basicHttpBinding and netTcpBinding; can't access HTTP endpoint具有 basicHttpBinding 和 netTcpBinding 的 WCF 服务;无法访问 HTTP 端点
【发布时间】:2010-12-10 18:55:02
【问题描述】:

我想使用 netTcpBinding 和 basicHttpBinding 提供相同的接口。我还想为两个端点提供 wsdl。当我访问http://localhost:9876/TestService/ 时,我在http://localhost:9876/TestService/?wsdl 获得了包含Tcp endoint 信息的mex 端点,但地址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>

【问题讨论】:

    标签: .net wcf wsdl wcf-binding wcf-configuration


    【解决方案1】:

    这是我的菜鸟错误。它实际上是正确的。答案在the post below。 当我点击基本 HTTP 类时,我只会得到浏览器的响应,但是使用这个 wsdl,我可以连接两个绑定。

    【讨论】:

      【解决方案2】:

      我怀疑你的服务端点地址有误:

      <endpoint address="/ws" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
                      name="Test" contract="CompanyX.AppServer.Interfaces.ITest" />
      

      因为它是一个相对地址(添加到您的基地址),它应该只是 ws - 没有前导正斜杠:

      <endpoint name="Test" 
                address="ws" 
                binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
                contract="CompanyX.AppServer.Interfaces.ITest" />
      

      试试不带正斜杠!应该这样工作。

      【讨论】:

      • 我试过没有它,但我也没有得到答案。我是从这个 Microsoft 链接中得到的:msdn.microsoft.com/en-us/library/ms733749.aspx
      • @Pascal:不确定基地址中的斜杠是否会导致问题:&lt;add baseAddress="http://localhost:9876/TestService/" /&gt; - 不使用它试试 - 有什么变化吗??
      • 抱歉浪费了您的时间。这是一个菜鸟 WCF 的错误。我在下面发布了答案,以供将来与我有同样疑问的任何人参考。非常感谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多