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

发布于 2024-10-07 09:14:11 字数 3218 浏览 0 评论 0原文

我想通过 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 技术交流群。

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

发布评论

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

评论(2

坚持沉默 2024-10-14 09:14:11

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.

洛阳烟雨空心柳 2024-10-14 09:14:11

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

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

尝试不使用正斜杠!应该这样工作。

I suspect your service endpoint address is wrong:

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

Since it's a relative address (added to your base address), it should be just ws - no leading forward slash:

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

Try it without the forward slash! Should work that way.

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