Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 代码中的WCF protobuf网络端点_C#_Wcf - Fatal编程技术网

C# 代码中的WCF protobuf网络端点

C# 代码中的WCF protobuf网络端点,c#,wcf,C#,Wcf,我想在我的代码中序列化wcf客户端,而不是使用app.config 主要问题是我不知道如何将protobuf支持从App.config移到代码中。 我需要这个原因是更充分的管理内部代码的变化,也考虑如果我更新服务引用,它将覆盖App.CONFIG,这是不好的。 我的例子是: WSHttpBinding clientBinding = new WSHttpBinding(); clientBinding.Security.Mode = SecurityMode.None; clientBindin

我想在我的代码中序列化wcf客户端,而不是使用app.config

主要问题是我不知道如何将protobuf支持从App.config移到代码中。 我需要这个原因是更充分的管理内部代码的变化,也考虑如果我更新服务引用,它将覆盖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>