使用 IEndpointBehavior 设置 WCF 绑定的传输安全性?

发布于 2024-10-03 02:23:11 字数 1681 浏览 12 评论 0原文

有没有办法在运行时设置 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
    }
}

是否可以更改安全模式?

Is there a way to set the transport security normally specified in the config of a basicHttpBinding at runtime, possibly by implementing IEndpointBehavior?

Essentially take this:

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

And use this (or something else) instead:

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

Is it possible to change the security mode?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声无音无过去 2024-10-10 02:23:11

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

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

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

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

I don't think it is possible to do this via an endpoint behavior. Behaviors can't amend the binding configuration early enough.

Howver, it can be done in code a different way. The BasicHttpBinding has a constructor overload which allows the security mode to be specified:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

This has to be done before the service is started, and assumes you are creating the ServiceHost and Endpoints yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文