如何以编程方式在wcf中编写端点配置c#

时间:2016-11-25 02:48:57

标签: c# wcf

我试图以编程方式创建端点配置,下面是生成的配置文件,我想使用c#以编程方式创建相同的配置。我想通过编程方式设置bindingConfiguration,contract,name,binding,address。

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IFakeService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:55536/FakeService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFakeService" contract="ChannelAdam.Wcf.BehaviourSpecs.TestDoubles.IFakeService" name="BasicHttpBinding_IFakeService" />
    </client>
  </system.serviceModel>

1 个答案:

答案 0 :(得分:1)

var binding = new BasicHttpBinding() {
    Name = "BasicHttpBinding_IFakeService",
    MaxBufferSize = 2147483647,
    MaxReceivedMessageSize = 2147483647
};

var endpoint = new EndpointAddress("http://localhost:55536/FakeService.svc");
MyInterfaceClient client = new MyInterfaceClient(binding, endpoint);