共用方式為


Changing BindingElement settings on a Binding.

We don’t allow you to modify the properties of the binding directly, but you can create a copy of the binding elements used to create a particular binding, alter the desired properties, then use the binding element collection to create a new custom binding.

 

 BasicHttpBinding basicBinding = new BasicHttpBinding();
BindingElementCollection bindingElementCollection = basicBinding.CreateBindingElements();
bindingElementCollection.Find<HttpTransportBindingElement>().KeepAliveEnabled = false;
CustomBinding myBasicBinding = new CustomBinding(bindingElementCollection);