Question

I'm developing a client-server app using WCF over the netTcpBinding.

My solution has 2 projects, the client one and the server one.

So far I've learnt that in order to get the WCF service working I have to do some configuration on the app.config file. This I did and things are working fine.

But now I have a problem finding out what to do when I deploy the service to a server, in order for the client to connect. My problem is that I don't know what I have to modify in the app.config (or any other location) when I deploy the service in to a location other than "localhost".

Here is my server app's app.config file:

<?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>

The "mex" endpoint and the http protocol base address are there in order for the client to get the metadata (I couldn't get it otherwise).

So, since I don't know beforehand what the IP address is where I'm going to deploy the server, I'd like the endpoint be read from a config or ini file (I would rather not have to compile for each endpoint).

Also, what do I have to modify on the client side? Here is the relevant section of the 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>

Any advice would be appreciated!

Was it helpful?

Solution

Config files are specific to an environment. Typically, you'll change (if needed) the localhost bit in service addresses to an IP address or name.

For clients it's the same. A production-client should be configured in its production environment to use the URL of the production service. Of course you can't configure the client until you know where the service will be located*.

Unfortunately you'll have to specify the URL for each client endpoint individually, for more info have a look at this related question. One alternative you could work out, is implementing your own setting for a client side "BaseAddress", and use that to programmatically specify endpoint addresses.


* If you're after some more extreme flexibility in locating services and clients, you could look into WCF Discovery mechanisms.


** As another side note, if you're looking to automate creating config files for different environments I can recommend using (for example) SlowCheetah.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top