【问题标题】:Set transport security on WCF binding using IEndpointBehavior?使用 IEndpointBehavior 在 WCF 绑定上设置传输安全性?
【发布时间】:2011-05-12 08:21:03
【问题描述】:

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

基本上是这样:

<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
    }
}

是否可以更改安全模式?

【问题讨论】:

    标签: c# .net wcf wcf-binding transport


    【解决方案1】:

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

    但是,它可以通过不同的方式在代码中完成。 BasicHttpBinding 有一个构造函数重载,允许指定安全模式:

    BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
    

    这必须在服务启动之前完成,并假设您正在自己创建 ServiceHost 和 Endpoints。

    【讨论】:

    • 是的,我的问题是我认为我无法控制绑定的创建。我正在使用第 3 方库,它采用 IList 的 arg 但不允许我指定绑定信息。
    • 我最终做了与您的建议类似的事情,并拦截了绑定的创建。这意味着我不能真正按照预期的方式使用 3rd 方配置,但这很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    • 2011-11-05
    相关资源
    最近更新 更多