使用 IEndpointBehavior 设置 WCF 绑定的传输安全性?
有没有办法在运行时设置 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为不可能通过端点行为来做到这一点。行为无法及早修改绑定配置。
但是,可以通过不同的方式在代码中完成。 BasicHttpBinding 有一个构造函数重载,允许指定安全模式:
这必须在服务启动之前完成,并假设您自己创建 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:
This has to be done before the service is started, and assumes you are creating the ServiceHost and Endpoints yourself.