Question

Guys I've been looking at a ton of blogs, SO posts this week and I am still unsure as to how I convert my WCF service from HTTP bindings to using Named Pipes. I think there are different ways to do it, but I am using the web.configs and using a service reference in my code.

Rather than detail everything here I've tried, can I ask this question?

What are the steps I need to take to go from HTTP Binding to Named Pipes?

Do I need this MEX thing I see mentioned in (some) blogs/SO posts? I know I need to set IIS to enabled protocols: net.pipe... and that IIS Express doesn't support this (that took an afternoon!)

Some relevant code, what I have right now:

in IEmployeeData:

namespace Mobile.ServiceLayer {
[ServiceContract]
public interface IEmployeeData
{ ... }

Calling the WCF service:

string endpointConfigName = "BasicHttpBinding_IEmployeeData";
        EmployeeSvcRef.EmployeeDataClient edc = new EmployeeSvcRef.EmployeeDataClient(endpointConfigName);
        EmployeeSvcRef.EmployeeListResponse emp = edc.EmployeeList();

WCF service web.config:

 <services>
  <service name="Mobile.ServiceLayer.EmployeeData">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:62734/EmployeeData" />
      </baseAddresses>
    </host>
  </service>

...

<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- 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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

client web.config:

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IEmployeeData" />

...

<client>
  <endpoint address="http://localhost:62734/EmployeeData.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_IEmployeeData" contract="EmployeeSvcRef.IEmployeeData"
    name="BasicHttpBinding_IEmployeeData" />

Like I said I've looked at SO posts and blogs but there's always a piece of the puzzle missing it seems!

EDIT: Client web.config after wizard:

<endpoint address="net.pipe://localhost/EmployeeData.svc/" binding="netNamedPipeBinding"
    bindingConfiguration="NewBinding0" contract="IEmployeeData"
    name="" kind="" endpointConfiguration="">
    <identity>
      <certificateReference storeName="My" storeLocation="LocalMachine"
        x509FindType="FindBySubjectDistinguishedName" />
    </identity>
  </endpoint>
Was it helpful?

Solution

Ok this is what I did. You may find it easier to use the built-in tools mentioned in Max's comments. Right click on a web.config and choose Edit WCF Configuration. Get the WCF service done first and, providing the endpoints are set up, running this on the client (right click it's web.config) will present you with a wizard.

SERVER WEB.CONFIG

Service name is the fully-qualified name of the interface e.g. Mobile.ServiceLayer.IEmployeeData

The base address changes to

net.pipe://localhost/EmployeeData.svc

. Notice the port number is removed and the .svc is present(!)

Create an endpoint, the contract being your interface and binding of type netNamedPipeBinding.

Add a second endpoint for MEX which is MetadataEXchange.

Set ServiceMetaData httpGetEnabled to false.

<system.serviceModel>
<services>
  <service name="Mobile.ServiceLayer.IEmployeeData">
    <host>
      <baseAddresses>
        <add baseAddress="net.pipe://localhost/EmployeeData.svc" />
      </baseAddresses>
    </host>
    <!-- NetPipe -->
    <endpoint
      address=""
      binding="netNamedPipeBinding"
      contract="IEmployeeData" name="MyNetPipe" />
    <!-- Mex (Net.Tcp / Net.Pipe ) -->
    <endpoint name="EmployeeDataNetPipeMex" address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

CLIENT WEB.CONFIG

Remove the binding entry from 'basicHttpBinding'

Add the section with an entry named NetNamedPipeBinding_IEmployeeData Inside 'client' add an endpoint with the address

net.pipe://localhost/EmployeeData.svc

the contract being the 'referencename'.'interface'

    <bindings>
  <basicHttpBinding>
  </basicHttpBinding>
  <netNamedPipeBinding>
    <binding name="NetNamedPipeBinding_IEmployeeData" />
  </netNamedPipeBinding>
</bindings>
<client>
  <endpoint address="net.pipe://localhost/EmployeeData.svc" binding="netNamedPipeBinding"
    bindingConfiguration="NetNamedPipeBinding_IEmployeeData" contract="EmployeeSvcRef.IEmployeeData"
    name="NetNamedPipeBinding_IEmployeeData" />
    </client>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top