具有basicHttpBinding和netTcpBinding的WCF服务;无法访问HTTP端点

时间:2010-12-10 18:55:02

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

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我怀疑您的服务端点地址错误:

<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" />

尝试没有正斜杠!应该那样工作。