【问题标题】:How to detect binding from wcf service end如何检测来自 wcf 服务端的绑定
【发布时间】:2014-03-06 01:13:22
【问题描述】:

假设我有一个具有多个端点的 wcf 服务,这些端点具有不同类型的绑定,例如 tcp、basichttp、wshttp 等。

<endpoint address ="" binding="wsHttpBinding"
                contract="NorthwindServices.ServiceContracts.ICustomerService"
                bindingNamespace = "http://dotnetmentors.com/services/customer" />
    <endpoint address="mex" binding="mexHttpBinding" 
                 contract="IMetadataExchange"/>

    <endpoint address ="" binding ="netNamedPipeBinding" 
                contract ="NorthwindServices.ServiceContracts.ICustomerService"
                bindingNamespace = "http://dotnetmentors.com/services/customer"  />
    <endpoint address="mex" binding="mexNamedPipeBinding" 
                 contract="IMetadataExchange"/>

因此客户端可以使用具有不同绑定的任何端点调用我的服务。当客户端拨打电话以及何时请求将转到服务端时,我如何以编程方式检测正在使用哪个绑定客户端...是 tcp、basichttp、wshttp 吗?

所以用代码示例指导我,它可以帮助我从服务中检测到哪个协议和绑定客户端正在使用。谢谢

【问题讨论】:

    标签: wcf wcf-binding wcf-endpoint


    【解决方案1】:

    你究竟为什么关心这个?总体而言,您的服务真的不应该关心客户端用于访问服务的绑定是否会影响服务行为(在这种情况下,拥有多个单独的服务可能真的更有意义)。

    也就是说,我认为一种可能的方法是查看服务的端点地址,我认为您可以使用类似这样的东西(未经测试):

    var opCtxt = OperationContext.Current;
    var epAddress = opCtxt.EndpointDispatcher.EndpointAddress;
    var uri = epAddress.Uri;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-22
      • 1970-01-01
      相关资源
      最近更新 更多