客户端app.config生成重复的端点[WCF]

时间:2011-09-08 15:41:17

标签: c# wcf app-config nettcpbinding

我有一个客户端使用我的localhost上的NetTCPBinding的服务引用生成其app.config。出于某种原因,当我在客户端上运行我的服务并更新服务引用时,app.config文件会复制端点(递增名称),而不是替换当前文件。

如何阻止客户端app.config复制端点?

这是我的服务app.config:

       

  <services>
    <service name="Embedded_DCC_Service.EmbeddedService" behaviorConfiguration="serviceBehavior">
      <endpoint
        name ="TCPEndPoint"
        binding="netTcpBinding"
        contract="Embedded_DCC_Service.IEmbeddedService"
        address="EmbeddedService"
        bindingConfiguration="EmbeddedService_Binding"
        />
      <endpoint
        name ="MetaDataTcpEndpoint"
        binding="mexTcpBinding"
        contract="IMetadataExchange"
        address="mex" 
        />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:9292/"/>
        </baseAddresses>
      </host>
    </service>
  </services>

  <bindings>
    <netTcpBinding>
      <binding name="EmbeddedService_Binding" closeTimeout="infinite" openTimeout="infinite"
          receiveTimeout="infinite" sendTimeout="infinite" />
    </netTcpBinding>
  </bindings>

  <behaviors>
    <serviceBehaviors>
      <behavior name="serviceBehavior">
        <serviceMetadata httpGetEnabled="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

</system.serviceModel>

客户端上生成的app.config(带有重复条目):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="TCPEndPoint" 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">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="Windows" />
          </security>
        </binding>
        <binding name="TCPEndPoint1" 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">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="Windows" />
          </security>
        </binding>
        <binding name="TCPEndPoint2" 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">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="Windows" />
          </security>
        </binding>
        <binding name="TCPEndPoint3" 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">
              <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint">
        <identity>
          <userPrincipalName value="user@mmi.local" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint1"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint1">
        <identity>
          <userPrincipalName value="user@mmi.local" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint2"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint2">
        <identity>
          <userPrincipalName value="user@mmi.local" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint3"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint3">
        <identity>
          <userPrincipalName value="user@mmi.local" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

2 个答案:

答案 0 :(得分:0)

您的问题看起来类似于this问题

它告诉我这是Visual Studio 2010中的一个已知错误,并告诉我检查link

答案 1 :(得分:-1)

你也可以编程方式尝试绑定,就像这样(你必须根据你的选择进行更改):

  BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
                binding.Name = "ActivationManagerSoap"; 
                binding.CloseTimeout = new TimeSpan(0, 5, 0); 
                binding.OpenTimeout = new TimeSpan(0, 5, 0); 
                binding.ReceiveTimeout = new TimeSpan(0, 5, 0); 
                binding.SendTimeout = new TimeSpan(0, 5, 0);
                binding.AllowCookies = false; 
                binding.BypassProxyOnLocal = false;
                binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; 
                binding.MaxBufferSize = 65536; binding.MaxBufferPoolSize = 524288;
                binding.MaxReceivedMessageSize = 65536;
                binding.MessageEncoding = WSMessageEncoding.Text;
                binding.TextEncoding = Encoding.UTF8;
                binding.TransferMode = TransferMode.Buffered;

                binding.UseDefaultWebProxy = true;
                XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas();
                quotas.MaxDepth = 32; 
                quotas.MaxStringContentLength = 8192; 
                quotas.MaxArrayLength = 16384; 
                quotas.MaxBytesPerRead = 4096;
                quotas.MaxNameTableCharCount = 16384;
                binding.ReaderQuotas = quotas;


                EndpointAddress addres = new EndpointAddress("http://xxxxxx/service");

                ActivationService.ActivationManagerSoapClient client = new ActivationService.ActivationManagerSoapClient(binding, addres);