4

I have started learning WCF and have created a few test http services successfully. Now, i was trying to create a self-hosted WCF service using net.pipe binding. Below is the configuration file for the service:-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
    <services>
        <service behaviorConfiguration="MEX" name="InProcService.MyService">
            <endpoint address="MyService"
                binding="netNamedPipeBinding" bindingConfiguration="" contract="InProcService.IMyService" />
            <endpoint address="Mex" binding="mexNamedPipeBinding"
                contract="IMetadataExchange" />
            <host>
                <baseAddresses>
                    <add baseAddress="net.pipe://localhost/InProcService/" />
                    <add baseAddress="http://localhost:8001/InProcService/" />
                </baseAddresses>
            </host>
        </service>
    </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="MEX"  >
        <serviceMetadata httpGetEnabled="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>
</configuration>

Now in my host application, I am starting the service using:-

        ServiceHost host = new ServiceHost(typeof(MyService));
        host.Open();
        Console.WriteLine("Service started");

        host.Close();

The service starts correctly when this code is executed.

Now, when in my client application, I try to add the service reference to this running service, it is not able to find it. Is there something which I am not doing or doing incorrectly?

I would appreciate any help I can get on this.

Cheers, Abhi.

Abhishek Jain
  • 2,957
  • 23
  • 35
  • What url are you passing to "Add Service Reference"? Exactly what error do you get? Also, try using the command-line svcutil.exe program - you should be able to see the errors. – John Saunders Jan 05 '11 at 16:15
  • How do you point to your service when adding service reference ? The endpoint address should look like this: net.pipe://localhost/InProcService/MyService – volpav Jan 05 '11 at 16:18
  • The error message said:- "Metadata contains a reference that cannot be resolved: 'net.pipe://localhost/InProcService/MyService'. There was no endpoint listening at net.pipe://localhost/InProcService/MyService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The pipe endpoint 'net.pipe://localhost/InProcService/MyService' could not be found on your local machine. If the service is defined in the current solution, try building the solution and adding the service reference again." Any ideas? – Abhishek Jain Jan 05 '11 at 16:25
  • In the Add Service Reference window, I am giving "net.pipe://localhost/InProcService/MyService" as the url – Abhishek Jain Jan 05 '11 at 16:26
  • 4
    What about adding Console.ReadKey() between WriteLine and Close? I guess your host is closed before you try to get reference. – Ladislav Mrnka Jan 05 '11 at 16:27
  • @Ladislav, I am too embarrased to say that IT was the problem. I feel like jumping out of the window. Thanks a lot. – Abhishek Jain Jan 05 '11 at 16:37

1 Answers1

2

The service is opened and closed after that. By the time you start the client the server is already closed. So Console.ReadKey() is required is requied before close.