部署使用netTcpBinding(非IIS托管)的WCF服务

部署使用netTcpBinding(非IIS托管)的WCF服务,wcf,wcf-binding,wcf-endpoint,Wcf,Wcf Binding,Wcf Endpoint,我正在开发一个客户端-服务器应用程序,使用WCF通过netTcpBinding 我的解决方案有两个项目,客户机项目和服务器项目 到目前为止,我了解到为了让WCF服务工作,我必须对app.config文件进行一些配置。我做到了,一切都很顺利 但是现在,为了让客户机连接,在将服务部署到服务器时,我发现了一个问题,即如何确定该做什么。我的问题是,当我将服务部署到“localhost”以外的位置时,我不知道必须在app.config(或任何其他位置)中修改什么 以下是我的服务器应用程序的app.conf

我正在开发一个客户端-服务器应用程序,使用WCF通过netTcpBinding

我的解决方案有两个项目,客户机项目和服务器项目

到目前为止,我了解到为了让WCF服务工作,我必须对app.config文件进行一些配置。我做到了,一切都很顺利

但是现在,为了让客户机连接,在将服务部署到服务器时,我发现了一个问题,即如何确定该做什么。我的问题是,当我将服务部署到“localhost”以外的位置时,我不知道必须在app.config(或任何其他位置)中修改什么

以下是我的服务器应用程序的app.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="MMServidor3.ServidorCliente">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
          contract="MMServidor3.iServicioMM">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:4005/MMServidor3/" />
            <add baseAddress="net.tcp://localhost:4006/MMServidor3/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

“mex”端点和http协议基址存在,以便客户端获取元数据(否则我无法获取元数据)

因此,由于我事先不知道将在哪里部署服务器的IP地址,所以我希望从配置文件或ini文件中读取端点(我宁愿不必为每个端点编译)

另外,我必须在客户端修改什么?以下是client app.config的相关部分:

<system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_iServicioMM" 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://localhost:4006/MMServidor3/" binding="netTcpBinding"
                bindingConfiguration="NetTcpBinding_iServicioMM" contract="MMServicioServidor.iServicioMM"
                name="NetTcpBinding_iServicioMM">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>


任何建议都将不胜感激

配置文件是特定于环境的。通常,您会将服务地址中的
localhost
位(如果需要)更改为IP地址或名称

对客户来说也是如此。生产客户机应在其生产环境中配置为使用生产服务的URL。当然,在知道服务将位于何处之前,您无法配置客户端*

不幸的是,您必须分别为每个客户端端点指定URL,有关更多信息,请参阅。您可以解决的另一个选择是实现您自己的客户端“BaseAddress”设置,并以编程方式使用该设置


*如果您希望在定位服务和客户方面有更大的灵活性,那么您可以考虑



**另一方面,如果您希望为不同的环境自动创建配置文件,我建议您使用(例如)。

下面给出了一个示例,说明如何在类似情况下使用模板工具: