我想知道如何为webHttpBinding禁用keepAlive。我知道我可以这样做:
<bindings>
<customBinding>
<binding name="WebHttpWithoutKeepAlive">
<webMessageEncoding />
<httpTransport keepAliveEnabled="false" />
</binding>
</customBinding>
</bindings>
<services>
<service name="MyService" behaviorConfiguration="myServiceBehavior">
<endpoint address="http://localhost:9005/"
binding="customBinding"
bindingConfiguration="WebHttpWithoutKeepAlive"
contract="IMyService"
behaviorConfiguration="myServerEndpointBehavior"/>
</service>
</services>
我如何以编程方式执行相同的操作?
答案 0 :(得分:4)
private Binding CreateBinding()
{
Binding binding = new WebHttpBinding();
CustomBinding customBinding = new CustomBinding(binding);
var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
transportElement.KeepAliveEnabled = false;
return customBinding;
}