2010-11-18 77 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