2

I'm creating my first WCF app. Client can communicate with host when those are on same computer, but failed from other computer on LAN. Both are console app.

Here is my code and config.

Client config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <system.serviceModel>
      <bindings>
         <wsHttpBinding>
            <binding name="WSHttpBinding_ICalculator" />
         </wsHttpBinding>
      </bindings>
      <client>
         <endpoint name="WSHttpBinding_ICalculator"
             address="http://192.168.100.6:8000/ServiceModelSamples/Service/CalculatorService"
             binding="wsHttpBinding" 
             bindingConfiguration="WSHttpBinding_ICalculator"
             contract="ServiceReference1.ICalculator">
             <identity>
                <userPrincipalName value="saumitra\skpaul" />
             </identity>
         </endpoint>
      </client>
   </system.serviceModel>
</configuration>

Host code:

class Program
{
    static void Main(string[] args)
    {
        // Step 1 Create a URI to serve as the base address.
        Uri baseAddress = new Uri("http://Localhost:8000/ServiceModelSamples/Service");

        // Step 2 Create a ServiceHost instance
        ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);

        try
        {
            // Step 3 Add a service endpoint.
            selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");

            // Step 4 Enable metadata exchange.
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            selfHost.Description.Behaviors.Add(smb);

            // Step 5 Start the service.
            selfHost.Open();
            Console.WriteLine("The service is ready.");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.WriteLine();
            Console.ReadLine();

            // Close the ServiceHostBase to shutdown the service.
            selfHost.Close();
        }
        catch (CommunicationException ce)
        {
            Console.WriteLine("An exception occurred: {0}", ce.Message);
            selfHost.Abort();
        }
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
s.k.paul
  • 7,099
  • 28
  • 93
  • 168
  • 2
    This sounds like a job for ... Firewall Man :-) – paxdiablo Mar 04 '15 at 05:02
  • Any idea how to solve it? – s.k.paul Mar 04 '15 at 05:04
  • Yes, change the firewall rules to allow incoming sessions to the specific port. But that's not really a programming question so much as one that should be over on ServerFault. You'll get "better" answers over there. – paxdiablo Mar 04 '15 at 05:05
  • What happens when you try to browse http://192.168.100.6:8000/ServiceModelSamples/Service/CalculatorService from client? – Amit Mar 04 '15 at 05:35
  • @Amit It says "the webpage is not available" – s.k.paul Mar 04 '15 at 05:49
  • Then you have connectivity issues. Solve those. Check for firewall setting for server and client and also check do you have on server as a valid user? – Amit Mar 04 '15 at 06:06
  • saumitra\skpaul is a valid user – s.k.paul Mar 04 '15 at 06:24
  • possible duplicate of [WCF error - There was no endpoint listening at](http://stackoverflow.com/questions/17572500/wcf-error-there-was-no-endpoint-listening-at) – N K Mar 04 '15 at 08:55

2 Answers2

1

You can get an idea from this post

You can also use Socket Programming. Here is a very good example for mutli-client, two-way communication socket programming.

Community
  • 1
  • 1
Code It
  • 396
  • 1
  • 6
0

First ensure that the address used from the client is the correct location of the server. Your code is currently hard coded to the destination as...

<endpoint address="http://192.168.100.6:8000/

...but is the server actually running on 192.168.100.6?

Phil Wright
  • 22,580
  • 14
  • 83
  • 137
  • Host is running as a console app on 192.168.100.6 and client is also a console app running on 192.168.100.7. – s.k.paul Mar 04 '15 at 05:11
  • Try running the WCF Client on the client machine to see if you can actually connect to the server address. https://community.dynamics.com/crm/b/workandstudybook/archive/2014/06/03/standalone-wcftestclient.aspx – Phil Wright Mar 04 '15 at 05:40