我在.clientconfig文件中配置了这样的绑定。
<customBinding>
<binding name="CustomBinding_MyService">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
我需要以编程方式构建相同的绑定(说实话,我只是这样做)。我的问题是,如何在C#中执行此操作?目前,我有
CustomBinding binding = new CustomBinding();
但是,我不确定从那里去哪里。谢谢!
最佳答案
它看起来像这样:
var customBinding = new CustomBinding(
new BinaryMessageEncodingBindingElement(),
new HttpTransportBindingElement()
{
MaxReceivedMessageSize = 2147483647,
MaxBufferSize = 2147483647
}
);
var endpoint = new EndpointAddress("http://www.myservice.com/myservice.svc");
var myServiceClient = new MyServiceClient(customBinding, endpoint);
myServiceClient.SayHelloAsync(); // Or whatever