以编程方式在Silverlight中构建WCF绑定

时间:2011-02-04 17:30:23

标签: c# silverlight wcf

我有一个在我的.clientconfig文件中配置的Binding。

<customBinding>
  <binding name="CustomBinding_MyService">
    <binaryMessageEncoding />
    <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
  </binding>
</customBinding>

我需要以编程方式构建这个相同的绑定(这是一个很长的故事,我只是这样做)。我的问题是,我如何在C#中做到这一点?目前,我有

CustomBinding binding = new CustomBinding();

但是,我不知道从那里去哪里。谢谢!

2 个答案:

答案 0 :(得分:5)

它看起来像这样:

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

答案 1 :(得分:-1)

希望这会有所帮助:Runtime data binding