<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <startup> 

        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

    </startup>

  <appSettings>

    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />

  </appSettings>

  <system.web>

    <compilation debug="true" />

  </system.web>

  

  <system.serviceModel>

    <behaviors>

      <serviceBehaviors>

        <behavior name="MyServiceBehavior">

          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <bindings>

      <wsDualHttpBinding>

        <binding name="dualHttpBinding" transactionFlow="true" maxReceivedMessageSize="100000"

          messageEncoding="Text" >

          <security mode="None">

            <message clientCredentialType="None" negotiateServiceCredential="false" />

          </security>

        </binding>

      </wsDualHttpBinding>

    </bindings>

    

    

    <services>

      <service behaviorConfiguration="MyServiceBehavior" name="service.MyPublisher" >

        <endpoint address="" binding="wsDualHttpBinding" contract="service.IMyContract" bindingConfiguration="dualHttpBinding">

          <!--<identity>

            <dns value="localhost"/>

          </identity>-->

          

        </endpoint>

        <!--<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />-->

        <endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange" />

        <host>

          <baseAddresses>

            <add baseAddress="http://192.168.0.139:8899/" />

          </baseAddresses>

        </host>

      </service>

    </services>

  </system.serviceModel>

</configuration>


以上是wsDualHTTPBinding的配置文件,wsDualHTTPBinding用于实现双向通信。红色部分加入之后,可以将服务器与客户端软件部署于不同的机器上(蓝色部分去除)。

如果没有下面这段红色部分:

          <security mode="None">

            <message clientCredentialType="None" negotiateServiceCredential="false" />

          </security>

客户端会出现如下异常报错:

The caller was not authenticated by the service.

部署于不同机器的另外一个需要注意的地方是:关闭防火墙。