Click here to Skip to main content
15,886,038 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to write a project in C# that uses WCF to have a server that multiple clients can connect to and get sent strings. It works fine on my development machine but when the client is running on a different machine to the server it always fails and I get an error on the clients console:
Unhandled Exception: System.ServiceModel.EndpointNotFoundException: There was no
 endpoint listening at http://henryhunt/SystemControllers/CalculatorService that
 could accept the message. This is often caused by an incorrect address or SOAP
action. See InnerException, if present, for more details. ---> System.Net.WebExc
eption: Unable to connect to the remote server ---> System.Net.Sockets.SocketExc
eption: A connection attempt failed because the connected party did not properly
 respond after a period of time or established connection failed because connect
ed host has failed to respond 192.168.1.64:80
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock
et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state,
IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStre
am()
   --- End of inner exception stack trace ---

I have checked the URL for the endpoint and it are the same as the server and I don't know what is wrong. Here is my App.config for the service:
XML
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="GettingStartedLib.CalculatorService">
        <host>
          <baseAddresses>
            <add baseAddress="http://henryhunt/SystemControllers/CalculatorService" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="wsHttpBinding" contract="GettingStartedLib.ICalculator"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="False" httpsGetEnabled="False" />
          <!-- 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="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

The following is the code for the host console not the actual service:
C#
static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://henryhunt/SystemControllers/");
            ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);

            try
            {
                selfHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "CalculatorService");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                selfHost.Open();
                Console.WriteLine("Press  to terminate service");
                Console.WriteLine();
                Console.ReadLine();

                selfHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception was thrown: {0}", ce.Message);
                selfHost.Abort();
            }
        }


This is the App.config file for the client:
XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_ICalculator" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://henryhunt/SystemControllers/CalculatorService"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator"
                contract="ServiceReference1.ICalculator" name="WSHttpBinding_ICalculator">
                <identity>
                    <userPrincipalName value="HENRYHUNT\Henry" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>


I really do not know why it cannot access the server from another computer and I have been trying for ages. Please help me, thank you.
Posted
Comments
Sergey Alexandrovich Kryukov 29-Dec-13 11:57am    
Hm... only one code fragment, just for service side... How about client side? One thing immediately looks suspicious: why URI in the server side. And what does it mean? Do you really have an HTTP server and DNS server pointing to "henryhunt"?
May I ask you what do you want achieve in general? The simplest self-hosted WCF service-client pair would look so-o simple...
—SA
Henry Hunt 29-Dec-13 12:15pm    
I have not posted any code for the service, only the host console that uses it. This is the code for the client which is also a console:

static void Main(string[] args)
{
CalculatorClient client = new CalculatorClient();

Console.WriteLine(client.Endpoint.Address);
Console.WriteLine(client.State);
Console.WriteLine(client.Endpoint.Name);
Console.WriteLine(client.Endpoint.ListenUri);


Console.WriteLine(client.Login("password"));
Console.WriteLine(client.Login("hello"));

double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

value1 = 145.00D;
value2 = 76.54D;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

value1 = 9.00D;
value2 = 81.25D;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

value1 = 22.00D;
value2 = 7.00D;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

client.Close();
Console.ReadKey();
}


Right, all I basically want is to have a computer. This computer will be downloading data from the internet and saving it (that part has nothing to do with WCF) and it will also run the server software. There will be lots of people on separate computers with a piece of software that will use the service to send a code back to the server. The server will then read that code and select the relevant piece of data (which it downloaded previously) to send back to the client (whether it be an image file or just a value). It is simple and I have it working absolutely perfectly with the client and server on the same machine, it sends the data back just like I want but the error occurs whenever I try to run the client on another machine from the server and I assumed it is a problem with how I have configured both the server and client.
Amey K Bhatkar 29-Dec-13 13:09pm    
Your URL is not public pointing. Is u client or consumer of service located on intranet? Have you ping your server from client machine or http://henryhunt/SystemControllers/CalculatorService. If you able to ping server then there is some problem with the binding. have you tested your wcf using wcf test client exe?
Henry Hunt 29-Dec-13 14:33pm    
Reading this, am I right in thinking that http is not the right 'thing' to be using because it is not hosted on a website or intranet or online? Should I be using the netTcpBinding instead so I use 'net.tcp://' instead of 'http://'? Maybe that it why it is not working, because it thinks its a service or file on a website not an endpoint?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900