wcf设置多绑定

我们经常会遇到这样的情形:访问服务的客户端可能来自各不相同的系统和应用程序。可以使用各不相同的绑定定义多个终结点,以允许不同的客户端平台用各自支持的传输协议来访问服务。

显示声明多个绑定:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="MyService">
        <endpoint
          address="http://localhost:8080/MyService"
          binding="wsHttpBinding"
          contract="IMyService" />
        <endpoint
          address="http://localhost:8080/MyService/basic"
          binding="basicHttpBinding"
          contract="IMyService" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

程序里增加了两个终结点,分别使用wsHttpBinding和basicHttpBinding。

这里要注意:首先,绑定不同;其次,地址不同。此外,如果要使用另一个不同的契约,那么终结点可以使用同一个地址和同一个绑定。如果地址不唯一,契约相同,也会出现异常。

 

2013-03-24

posted @ 2013-03-24 22:46  woshiliyuan  阅读(380)  评论(1编辑  收藏  举报