2010-11-18 75 views
0

有没有办法在运行时设置basicHttpBinding配置中通常指定的传输安全性,可能是通过实现IEndpointBehavior?使用IEndpointBehavior在WCF绑定上设置传输安全性?

本质借此:

<binding name="DfsAgentService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1000000" maxBufferPoolSize="10000000" maxReceivedMessageSize="1000000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> 
       <security mode="None"/><!--Transport--> 
      </binding> 

,并使用此(或别的东西),而不是:

namespace Endpoints { 
    class DfsEndpoint : IEndpointBehavior{ 


     #region IEndpointBehavior Members 

     void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) { 
      throw new NotImplementedException(); 
     } 

     void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { 
      throw new NotImplementedException(); 
     } 

     void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { 
      throw new NotImplementedException(); 
     } 

     void IEndpointBehavior.Validate(ServiceEndpoint endpoint) { 
      throw new NotImplementedException(); 
     } 

     #endregion 
    } 
} 

是否有可能改变安全模式?

回答

0

我不认为有可能通过端点行为来做到这一点。行为不能及早修改绑定配置。

无论如何,它可以用不同的方式在代码中完成。该basicHttpBinding的有一个构造函数重载它允许指定的安全模式:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); 

这样做的服务启动之前完成,并假设你正在创建ServiceHost的和端点自己。

+0

是的,我的问题是,我不认为我能控制绑定的创建。我正在使用一个采用IList 的arg的第三方库,但否则不允许指定绑定信息。 – 2010-11-19 17:06:09

+0

我最终做了一些类似于你的建议,并截获了绑定的创建。这意味着我无法按照预期的方式真正使用第三方配置,但这很好。 – 2010-12-17 22:24:29