【问题标题】:Deploying a WCF service that uses netTcpBinding (not IIS hosted)部署使用 netTcpBinding(非 IIS 托管)的 WCF 服务
【发布时间】:2012-10-22 01:49:46
【问题描述】:

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

我的解决方案有 2 个项目,客户端一个,服务器一个。

到目前为止,我了解到为了让 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 文件中读取端点(我宁愿不必为每个端点)。

另外,我必须在客户端修改什么?以下是客户端 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>

任何建议将不胜感激!

【问题讨论】:

标签: wcf wcf-binding wcf-endpoint


【解决方案1】:

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

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

不幸的是,您必须单独指定每个客户端端点的 URL,有关更多信息,请查看 this related question。您可以解决的另一种选择是为客户端“BaseAddress”实现您自己的设置,并以编程方式使用它来specify endpoint addresses


* 如果您希望在定位服务和客户方面更加灵活,可以查看WCF Discovery mechanisms


** 另外,如果您希望为不同环境自动创建配置文件,我可以推荐使用(例如)SlowCheetah

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多