none
How to create named pipe WCF EXE using net.pipe?? RRS feed

  • Question

  • I have created the .NET console application as below:

    [ServiceContract(Namespace = "WCFTest")]

        public interface ICalculator

        {

            [OperationContract]

            Double Add(Double n1, Double n2);       

        }

        [ServiceBehavior]

        public class CalculatorService : ICalculator

        {

            [OperationBehavior]

            public Double Add(Double num1, Double num2)

            {

                Double answer = num1 + num2;

                Console.WriteLine("Call made: Add({0},{1})", num1, num2);

                Console.WriteLine("Answer: {0}", answer);

                return answer;

            }

        }

     

    static void Main(string[] args)

    {

    Uri baseAddr = new Uri("net.pipe://localhost/WCFService1");

    ServiceHost localHost = new ServiceHost(typeof(CalculatorService), baseAddr);
          localHost.AddServiceEndpoint(typeof(ICalculator), new NetNamedPipeBinding(), "CalculatorService");
          localHost.Open();
     
    localHost.Open();

          Console.WriteLine("Service initialized.");

          Console.WriteLine("Press the ENTER key to terminate service.");

          Console.ReadLine();

          localHost.Close();

    }

    Now when i am tryin to generate the proxy class for using svcutil then svcutil is throwing the error. I am using the command as follwos:
    svcutil net.pipe://localhost/WCFService1 /out:test.cs
    =========================================================================
    Below is the error:


    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648]
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Attempting to download metadata from 'net.pipe://localhost/WCFService1' using WS
    -Metadata Exchange. This URL does not support DISCO.
    Microsoft (R) Service Model Metadata Tool
    [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648]
    Copyright (c) Microsoft Corporation.  All rights reserved.

    Error: Cannot obtain Metadata from net.pipe://localhost/WCFService1

    If this is a Windows (R) Communication Foundation service to which you have acce
    ss, please check that you have enabled metadata publishing at the specified addr
    ess.  For help enabling metadata publishing, please refer to the MSDN documentat
    ion at http://go.microsoft.com/fwlink/?LinkId=65455.


    WS-Metadata Exchange Error
        URI: net.pipe://localhost/WCFService1

        Metadata contains a reference that cannot be resolved: 'net.pipe://localhost
    /WCFService1'.

        There was no endpoint listening at net.pipe://localhost/WCFService1 that cou
    ld accept the message. This is often caused by an incorrect address or SOAP acti
    on. See InnerException, if present, for more details.

    If you would like more help, type "svcutil /?"

    ==================================================================================

    Can someone please help me how to resolve this error??

    • Edited by CoolBoy79 Monday, May 11, 2009 10:59 AM wrong code posted
    Monday, May 11, 2009 10:56 AM

Answers

  • Hi,

    Firts of all make sure you do not call twi Open()

    localHost.Open(); localHost.Open();

    Second, to get metadata for net.pipe you need to add the following code before call Open method

    ServiceMetadataBehavior serviceMetadataBehavior = localHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
    if (serviceMetadataBehavior == null)
    {
        serviceMetadataBehavior = new ServiceMetadataBehavior();
        localHost.Description.Behaviors.Add(serviceMetadataBehavior);
    }
    localHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(), "net.pipe://localhost/service/mex");
    And than you could use "net.pipe://localhost/service/mex" to generate proxy

    Read about net.pipe here http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx

    Regards
    • Marked as answer by Marco Zhou Wednesday, May 13, 2009 5:59 AM
    Monday, May 11, 2009 3:09 PM

All replies

  • You have to add an additional MEX endpoint. See this guide how to achieve this. Note that the HttpGet with the URL parameter "?wsdl" is not applicable for your named pipe endpoint.
    http://blogoscoped.com/archive/2005-08-24-n14.html
    Monday, May 11, 2009 11:20 AM
  • i have tried this as well but for me if i use http protocol then it's working fine for me. It's able to genearet the proxy file as well app.config file but when i use the named pipe then i am unable to generate the proxy as well and appconfig file. I am getting the saem error as i mention earlier. Could you please post some example hot to use named pipe binding in case of IPC using WCF???
    Monday, May 11, 2009 11:25 AM
  • Hi,

    Firts of all make sure you do not call twi Open()

    localHost.Open(); localHost.Open();

    Second, to get metadata for net.pipe you need to add the following code before call Open method

    ServiceMetadataBehavior serviceMetadataBehavior = localHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
    if (serviceMetadataBehavior == null)
    {
        serviceMetadataBehavior = new ServiceMetadataBehavior();
        localHost.Description.Behaviors.Add(serviceMetadataBehavior);
    }
    localHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(), "net.pipe://localhost/service/mex");
    And than you could use "net.pipe://localhost/service/mex" to generate proxy

    Read about net.pipe here http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx

    Regards
    • Marked as answer by Marco Zhou Wednesday, May 13, 2009 5:59 AM
    Monday, May 11, 2009 3:09 PM