下面是服务端的配置文件。服务端终结点地址是http://localhost:3721/calculatorservice,逻辑地址和物理地址统一,物理地址就是监听地址。
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true"
httpGetUrl="http://localhost:3721/calculatorservice/metadata" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Artech.WcfServices.Service.CalculatorService"
behaviorConfiguration="metadataBehavior" >
<endpoint address="http://localhost:3721/calculatorservice"
binding="wsHttpBinding"
contract="Artech.WcfServices.Service.Interface.ICalculator" />
</service>
</services>
</system.serviceModel>
</configuration>
下面给出客户端的配置文件。通过clientViaBehavior这个终结点行为指定终结点的物理地址,而通过endpoint的address节点指定的地址是逻辑地址。
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="clientViaBehavior">
<clientVia viaUri="http://127.0.0.1:3722/calculatorservice"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://127.0.0.1:3721/calculatorservice" binding="wsHttpBinding"
contract="Artech.WcfServices.Service.Interface.ICalculator"
name="calculatorservice"
behaviorConfiguration ="clientViaBehavior"/>
</client>
</system.serviceModel>
</configuration>
下面配置tcpTrace的监听地址和转发地址。tcpTrace就是一个消息的中介,客户端本来要将消息发送给3721,现在先将消息发送给3722,再转发给3721。
启动服务,执行服务调用,tcpTrace可以截获服务的请求和回复消息。