none
WCF Connection Problem - Named Pipes/TCP/HTTP RRS feed

  • Question

  •  I started writing my 1st hello WCF application this based on Michele Leroux Bustamante MSDN Webcast found here:

    http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?culture=en-US&EventID=1032344313&CountryCode=US

    I am using Vista Ultimate running VS2008 as an administrator.  Windows Firewall has been disabled.  SAV has also been disabled.  I am logged in as an administrator.

    Here is my server side setup code:

      

     

     private void ActivateHost()

            {

     

                using (ServiceHost serviceHost = new ServiceHost(typeof(PersonFactory)))

                {

                    serviceHost.AddServiceEndpoint(typeof(IPersonFactory), new NetNamedPipeBinding(), "net.pipe://localhost/PersonFactory");

                    serviceHost.AddServiceEndpoint(typeof(IPersonFactory), new NetTcpBinding() , "net.tcp://localhost:9000/PersonFactory");

                    serviceHost.AddServiceEndpoint(typeof(IPersonFactory), new BasicHttpBinding(), "http://localhost:9001/PersonFactory");

                    serviceHost.Open();

                }

            }

     

    When I try and consume these services using this code:

     

                try

                {

                    IPersonFactory proxy1 = ChannelFactory<IPersonFactory>.CreateChannel(new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/PersonFactory"));

                    Console.WriteLine(proxy1.Echo("Hello World"));

                }

                catch (EndpointNotFoundException namedPipeException)

                {

                    Console.WriteLine("-----Named Pipes Exception-----");

                    Console.WriteLine(namedPipeException.InnerException.Message);

                }

                try

                {

                    IPersonFactory proxy2 = ChannelFactory<IPersonFactory>.CreateChannel(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:9000/PersonFactory"));

                    Console.WriteLine(proxy2.Echo("Hello World"));

                }

                catch (EndpointNotFoundException tcpException)

                {

                    Console.WriteLine("-----TCP Exception-----");

                    Console.WriteLine(tcpException.InnerException.Message);

                }

     

                try

                {

                    IPersonFactory proxy3 = ChannelFactory<IPersonFactory>.CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://localhost:9001/PersonFactory"));

                    Console.WriteLine(proxy3.Echo("Hello World"));

                }

                catch (EndpointNotFoundException httpException)

                {

                    Console.WriteLine("-----HTTP Exception-----");

                    Console.WriteLine(httpException.InnerException.Message);

                }

     

    I get the following output. 

    -------Start Client

    -----Named Pipes Exception-----

    The pipe endpoint 'net.pipe://localhost/PersonFactory' could not be found on your local machine.

    -----TCP Exception-----

    No connection could be made because the target machine actively refused it 127.0.0.1:9000

    -----HTTP Exception-----

    Unable to connect to the remote server

    ---------End Client

    Finally, when I try and telnet to the service, I get the following response:

    C:\>telnet localhost 9000

    Connecting To localhost...Could not open connection to the host, on port 9000: Connect failed

     

    I searched these forums and other people are having problems with Vista and WCF, but aside from the port issue, I didn’t see a resolution.  Does anyone have any other ideas about where I can look – I am 99% sure this is a machine configuration issue, not an issue with my code.

     

    Thanks






    Sunday, November 8, 2009 2:04 AM

Answers

  • Hi Jamie,
    You are seeing these errors becuase in the following C#'s 'using' code pattern:
    using (ServiceHost serviceHost = new ServiceHost(typeof(PersonFactory)))
    {
    .....
    }
    once you come out of the closing brace, the serviceHost object is disposed, so essentially when the client is trying to call that service, it is not up becuase the service host has been shut down and hence you get the endpointnotfound exception.
    If you are using a Console application, you can insert a Console.ReadLine before the closing brance so that once the service host starts up, it waits for a user prompt to shutdown rather than shutting down automatically. Otherwise what you can do is to not use this pattern, rather open it up explicitly without the using block and then close it explicitly when you no longer need the service.
    Thanks.


    - Piyush
    • Marked as answer by Jamie_Dixon Sunday, November 8, 2009 11:01 AM
    Sunday, November 8, 2009 10:05 AM
    Moderator

All replies

  • Hi Jamie,
    You are seeing these errors becuase in the following C#'s 'using' code pattern:
    using (ServiceHost serviceHost = new ServiceHost(typeof(PersonFactory)))
    {
    .....
    }
    once you come out of the closing brace, the serviceHost object is disposed, so essentially when the client is trying to call that service, it is not up becuase the service host has been shut down and hence you get the endpointnotfound exception.
    If you are using a Console application, you can insert a Console.ReadLine before the closing brance so that once the service host starts up, it waits for a user prompt to shutdown rather than shutting down automatically. Otherwise what you can do is to not use this pattern, rather open it up explicitly without the using block and then close it explicitly when you no longer need the service.
    Thanks.


    - Piyush
    • Marked as answer by Jamie_Dixon Sunday, November 8, 2009 11:01 AM
    Sunday, November 8, 2009 10:05 AM
    Moderator
  • <Sound of me slapping my head>
     So I guess it was less than a 99% chance it was the machine configuration issue
     Thanks Piyush - I had Console.ReadLine() further on down the calling method
    </Sound of me slapping my head>
    Sunday, November 8, 2009 11:01 AM