我想在我的代码中使用wcf客户端而不是使用app.config。
主要问题是我不知道如何将我的App.config中的protobuf支持移动到我的代码中。 我需要这个原因是更多用户管理代码内部的更改,考虑如果我更新服务引用它将覆盖app.config并且它不是很好。
我的例子:
WSHttpBinding clientBinding = new WSHttpBinding();
clientBinding.Security.Mode = SecurityMode.None;
clientBinding.MaxReceivedMessageSize = 10000000;
const string _serverlink = "http://localhost:56142/SimpleService.svc";
using (TestClient client = new TestClient (clientBinding, new EndpointAddress(_serverlink )))
{ //do something }
的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="protoEndpointBehavior">
<protobuf/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ISimpleService" maxBufferPoolSize="20097152" maxReceivedMessageSize="20097152">
<security mode="None"/>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:56142/SimpleService.svc" behaviorConfiguration="protoEndpointBehavior"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISimpleService"
contract="SimpleHttp.ISimpleService" name="WSHttpBinding_ISimpleService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<extensions>
<behaviorExtensions>
<add name="protobuf" type="ProtoBuf.ServiceModel.ProtoBehaviorExtension, protobuf-net, Version=2.0.0.668, Culture=neutral, PublicKeyToken=257b51d87d2e4d67"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>