.NET Web服务使用WEB CONFIG设置硬编码网络TCP

时间:2014-08-16 06:46:01

标签: c# asp.net .net wcf tcp

我想确认一些事情。

以下是我在ASP.NET应用程序中调用WCF Web服务的方法。

var xml = "my xml string";
var ep = new EndpointAddress("http://myendpoint");
xml = new Proxy.ServiceClient(new NetTcpBinding(), ep).getNewXML(new Proxy.CallContext(), xml);

我的网络配置与下面的内容类似。我的问题是,即使这些设置在Web配置中,我上面的调用正在新建服务客户端并且每次都有新的TCP绑定这一事实告诉我这些设置没有被引用。这是正确的基于上述吗?

 <system.serviceModel>
  <bindings>
   <netTcpBinding>
    <binding name="NetTcpBinding_SCSService" closeTimeout="00:01:00"
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
     transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
     hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
     maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
      maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     <reliableSession ordered="true" inactivityTimeout="00:10:00"
      enabled="false" />
     <security mode="Transport">
      <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
      <message clientCredentialType="Windows" />
     </security>
    </binding>
   </netTcpBinding>
  </bindings>
  <client>
   <endpoint address="net.tcp://myendpoint"
    binding="netTcpBinding" bindingConfiguration="NetTcpBinding_SCSService"
    contract="Proxy.Service" name="NetTcpBinding_SCSService">
    <identity>
     <userPrincipalName value="user@user.com" />
    </identity>
   </endpoint>
  </client>
 </system.serviceModel>

1 个答案:

答案 0 :(得分:0)

那是对的。在这种情况下,您没有使用配置文件中的配置设置。

代理通常派生自抽象类ClientBase<T>,它提供了几种不同的方法来创建客户端代理的实例。列出的一些构造函数将使用所有配置文件,而其他构造函数将尝试使用配置文件来填充构造函数中未明确提供的信息。甚至有构造函数重载,根本不使用ClientBase<TChannel>(Binding, EndpointAddress)就是其中之一的配置文件。

如果您想使用应用程序配置文件中的内容,可以使用:

var client = new Proxy.ServiceClient("NetTcpBinding_SCSService");