【问题标题】:How config file would look at service end for multiple endpoint配置文件如何查看多个端点的服务端
【发布时间】:2013-01-04 14:58:17
【问题描述】:

我正在使用创建 svc 文件的 wcf 服务应用程序。现在我想设计我的服务,使人们可以通过 http url 和 tcp url 连接到我的服务

所以我想在我的配置中添加三个端点,一个用于 wshttp,一个用于 wsDualhttp,另一个用于 tcp。所以请有人给我示例配置条目,其中包含 wshttp、wsDualhttp 和 tcp 的 3 个端点。

在这种情况下,我是否需要为 wshttp、wsDualhttp 和 tcp 设置三个不同的 mex 端点。

还告诉我 3 个 url,我可以通过它在客户端创建代理类。谢谢

【问题讨论】:

  • 你为什么要清除所有你的答案。
  • 看看这个网址,tomasr 说了什么stackoverflow.com/questions/1212443/callback-with-nettcpbinding
  • 抱歉,我不在,对netTcpBinding 不再完全确定。阅读它:是的,确实 - 似乎你可以使用该绑定进行双工通信 - 但这是 在 IIS 中工作的一个选项 - 如果你想使用netTcpBinding 进行双工通信,那么您必须使用自托管。我从来没有尝试过或做过这个 - 所以我有点惊讶这似乎有效。
  • 感谢您回来。 IIS7 支持 netTcpBinding。如果你搜索谷歌,那么你会得到很多文章。

标签: wcf


【解决方案1】:

你可以有这样的东西(假设自托管,因为只有这样你才能真正确定自己的完整服务地址 - 托管在 IIS 中,服务地址主要取决于你的 .svc 文件所在的位置) :

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="YourNamespace.YourService" behaviorConfiguration="Default">
        <endpoint name="Default" 
            address="http://YourServer/Services/MyService" 
            binding="basicHttpBinding" 
            contract="YourNamespace.IYourService"/>
        <endpoint name="TCP" 
            address="net.tcp://YourServer/ServicesTCP/MyService" 
            binding="netTcpBinding" 
            contract="YourNamespace.IYourService"/>
        <endpoint name="mex" 
            address="http://YourServer/Services/MyService/mex" 
            binding="mexHttpBinding" 
            contract="IMetadataExchange"/>
        <endpoint name="Dual" 
            address="http://YourServer/Services/MyService/Dual" 
            binding="wsDualHttpBinding" 
            clientBaseAddress="http://localhost:8001/client/"
            contract="YourNamespace.IYourDualService"/>
      </service>
    </services>
  </system.serviceModel>

这将定义三个端点

  • http://YourServer/Services/MyService 为您的服务提供一个 HTTP 端点
  • http://YourServer/Services/MyService/mex 的 HTTP MEX 端点,用于元数据交换(服务可发现性)
  • net.tcp://YourServer/ServicesTCP/MyService 为您的服务提供一个 Net.TCP 端点

您当然也可以使用两个基地址来使配置更简单:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="YourNamespace.YourService" behaviorConfiguration="Default">
        <host>
          <baseAddresses>
            <add baseAddress="http://YourServer/Services"/>
            <add baseAddress="net.tcp://YourServer/ServicesTCP"/>
          </baseAddresses>
        </host>
        <endpoint name="Default" 
            address="MyService" 
            binding="basicHttpBinding" 
            contract="YourNamespace.IYourService"/>
        <endpoint name="TCP" 
            address="MyService" 
            binding="netTcpBinding" 
            contract="YourNamespace.IYourService"/>
        <endpoint name="mex" 
            address="MyService/mex" 
            binding="mexHttpBinding" 
            contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>

这将配置等效的服务端点。

wsDualHttpBinding 的不同之处在于它至少需要一个clientBaseAddress 用于回调机制(WCF 服务将回调您的客户端以发回例如状态消息) - 所以它需要一些额外的调整并且它不能真正固定到在wsHttpBinding 上工作的现有服务上 - 它需要单独完成。但是基本上 - 几乎都是一样的......

更新:在阅读了该主题后(这不是我经常使用的东西),似乎确实可以使用netTcpBinding 进行双向通信,但前提是您自己-托管您的服务 - IIS 不支持通过netTcpBinding 进行双工通信。

创建双工服务仍然需要额外的步骤和额外的代码 - 因此您不能真正拥有同时使用 basicHttpBindingwsHttpBinding 的非双工服务和双工服务。因此,在此示例中使用wsDualHttpBinding 拥有另一个端点确实没有意义,因为该服务要么需要真正的双工(然后您可以使用wsDualHttpBindingnetTcpBinding) - 或者它不是双工的 - 然后你可以使用basicHttpBindingwsHttpBindingnetTcpBinding 和更多“异国情调”的绑定(如 MSMQ、命名管道等)

【讨论】:

  • 感谢您的好回答。您已经给出了两组配置条目,但您没有说明第二组配置详细信息的三个端点地址是什么。我会为第二组配置条目写入 3 个端点地址。
  • 我了解多少...你说可以为 wshttp 和 tcp 等端点开发服务,但是当服务将具有 wshttp 绑定时,wsDualHttpBinding 是不可能的...我是对的。所以告诉我我不能开发一个只有两个端点的服务,一个是 wsDualHttpBinding,另一个是 tcp 端点?假设我正在开发一个将托管在 IIS 中的聊天应用程序。我希望人们可以使用 wsDualHttpBinding 并使用 tcp 绑定连接到我的服务....当服务托管在 IIS 中时是否不可能?请帮我理解。谢谢
  • 对不起,我明白了...客户端看到的 URL 在这两种情况下都是完全相同的。谢谢
  • wsDualHttpBinding 和 tcp 都支持双工......所以一个服务可能有两个端点用于 wsDualHttpBinding 和 tcp。我说的对吗?
  • 但是我看到了一个双工的聊天应用程序,它只有一个名为 tcp 的绑定并托管在 win 应用程序中......可能是我错了,因为我现在正在学习 wcf。但是请看看网址并下载应用程序并查看该聊天的代码,您肯定会看到它只有一个名为 tcp 的绑定,并且有一种回调技术……我的意思是双工。这是网址codeproject.com/Articles/25261/A-WCF-WPF-Chat-Application
猜你喜欢
  • 2011-09-19
  • 1970-01-01
  • 1970-01-01
  • 2013-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多