omaestra
omaestra

Reputation: 69

Use remote WCF Service

I'm having trouble with a Client-Server Application I'm developing.

I've created a Windows Form Application for the Client Part and a WCF Application for the Server part. I'm using Visual Studio 2010. The application works just fine locally but I need to separate them. I want to run the Server application in a remote PC connected to the same LAN as the Client App.

Every time I debug my Server application, it runs at "http:/ /localhost:port" but I need it to run at "http:/ /192.168.1.xxx:port". So that I can import the services to my Client App using that address: "http:/ /192.168.1.xxx:port/Service1.svc".

I have another question. How can I export my Server Application to run it wherever I want? i.e. How to run my server app without debugging it on Visual Studio 2010?.

These are my configuration files for my services:

Client Side (app.config):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IValidacionesService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocalhostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
            <binding name="BasicHttpBinding_IEncuestaCRUDService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="6553600" maxBufferPoolSize="52428800" maxReceivedMessageSize="6553600"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="3200" maxStringContentLength="819200" maxArrayLength="1638400"
                    maxBytesPerRead="409600" maxNameTableCharCount="1638400" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http:/ /localhost:2504/ValidacionesService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IValidacionesService"
            contract="ServiceValidacionesReference.IValidacionesService"
            name="BasicHttpBinding_IValidacionesService" />
        <endpoint address="http:/ /localhost:2504/EncuestaCRUDService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEncuestaCRUDService"
            contract="ServiceEncuestaReference.IEncuestaCRUDService" name="BasicHttpBinding_IEncuestaCRUDService" />
    </client>
</system.serviceModel>

Server Side (web.config):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings>
<add name="CADBEntities" connectionString="metadata=res://*/ModeloCaDB.csdl|res://*/ModeloCaDB.ssdl|res://*/ModeloCaDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=OMSUser\SQLEXPRESS;initial catalog=CADB;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Thanks in advance.

Upvotes: 0

Views: 647

Answers (2)

Derek W
Derek W

Reputation: 10046

Your client is trying to communicate with an EndpointAddress set to localhost which means the current computer.

It must be configured to contact the IP address of the machine that the WCF Service is being hosted on.

Here is an example of how you would do this in the client configuration file.

<system.serviceModel>
    <client>
      <endpoint address="http://192.168.1.xxx:port/Service1.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IValidacionesService"
          contract="IValidacionesService" name="BasicHttpBinding_IValidacionesService">
      </endpoint>  
    </client>
</system.serviceModel>

Upvotes: 0

dbugger
dbugger

Reputation: 16464

You need to host the WCF service as an IIS site on the other computer.

VS has a a couple of ways you can publish the files needed to the other machine, though the easiest way is probably via a network share.

Here's a link to the basics of publishing a WCF service.

Upvotes: 1

Related Questions