如何使用c#代码添加bindingConfiguration属性(WCF)

时间:2015-09-21 03:58:25

标签: wcf app-config wcf-binding

我在app.config中有一个端点:

<endpoint address=""

              binding="netTcpBinding"

              bindingConfiguration="financeBinding"

              name="RoutingServiceEndpoint"
              contract="System.ServiceModel.Routing.IRequestReplyRouter" />

app.config中的bindingConfiguration

    <bindings>
<netTcpBinding>
    <binding name="financeBinding" closeTimeout="00:10:10" openTimeout="00:10:10" sendTimeout="00:10:10" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
      <!--transactionFlow="true"-->
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None" />
    </binding>
  </netTcpBinding>
</bindings>

问题是:如何在代码中配置?我需要读取数据库的配置并绑定它。 :)

1 个答案:

答案 0 :(得分:2)

使用此功能,您可以在代码中配置设置:

using System.ServiceModel;           

EndpointAddress endpoint = new EndpointAddress("http://yourAdress.svc");
NetTcpBinding binding = new NetTcpBinding();
binding.Name = "financeBinding";
binding.MaxBufferPoolSize = 2147483647;

binding.ReaderQuotas.MaxDepth = 2147483647;
binding.ReaderQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;

binding.OpenTimeout = new TimeSpan(0, 10, 10);
binding.CloseTimeout = new TimeSpan(0, 10, 10);
binding.SendTimeout = new TimeSpan(0, 10, 10);

binding.Security.Mode = SecurityMode.None;
yourClient client = new yourClient(binding, endpoint);