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

发布于 2024-12-03 11:52:57 字数 8036 浏览 5 评论 0原文

我有一个客户端,它使用本地主机上的 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="[email protected]" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint1"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint1">
        <identity>
          <userPrincipalName value="[email protected]" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint2"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint2">
        <identity>
          <userPrincipalName value="[email protected]" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint3"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint3">
        <identity>
          <userPrincipalName value="[email protected]" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

I have a client that generates its app.config using a Service Reference to a NetTCPBinding over my localhost. For some reason when I run my service and Update the Service Reference on the client the app.config file duplicates the endpoints (incrementing the name) instead of replacing the current file.

How can I stop the client app.config from duplicating the endpoints?

Here is my service 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>

And the generated app.config on the client (with duplicate entries):

<?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="[email protected]" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint1"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint1">
        <identity>
          <userPrincipalName value="[email protected]" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint2"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint2">
        <identity>
          <userPrincipalName value="[email protected]" />
        </identity>
      </endpoint>
      <endpoint address="net.tcp://localhost:9292/EmbeddedService"
          binding="netTcpBinding" bindingConfiguration="TCPEndPoint3"
          contract="ServiceReference1.IEmbeddedService" name="TCPEndPoint3">
        <identity>
          <userPrincipalName value="[email protected]" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清欢 2024-12-10 11:52:57

看起来您的问题类似于这个问题

它告诉我们这是 Visual Studio 2010 中的一个已知错误,并要求检查此 链接

Looks like your question is similar to this question

It tells that this is a known bug in visual studio 2010 and tells to check this link.

在梵高的星空下 2024-12-10 11:52:57

您还可以以编程方式尝试绑定,如下所示(您必须根据您的选项进行更改):

  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);

you can also try the binding programatically , like this (you will have to change as per your options):

  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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文