Monthly Archives: January 2014

Test WCF Service from the MEX binding for NamedPipe Connection

Test WCF Service from the MEX binding for NamedPipe Connection

It when into the trouble when, there was requirement to change the WCF binding from TCP to NamedPipe for one of the project

The problem was, there were two WebSites, which were hosting the WCF Service. One service in each one of the website.

Now, as for the TCP Binding, website where separated by the port number. So, base address was something like

Net.tcp://localhost:6200/Service1.svc

Net.tcp://localhost:6400/Service2.svc

But, when doing for the NamedPipe, there aren’t port numbers in NamedPipe. So, it needed to have scheme like net.pipe://{someuniquename}/Service1.svc

But, the problem was, service was hosted in the WAS under IIS. I have no control on the addresses, as it would be dictated by the IIS

View my last post, which mention how to enter IIS binding Information to get unique hostname for namedpipe configuration

Now, I have added ABC and DEF in the binding information for each site. Now, my namedpipe endpoint address where

net.pipe://ABC/Service1.svc

net.pipe://DEF/Service2.svc

Now, I have my Server side, Host Endpoint as following

   1: <service name="ABC.Service.AuthenticationGateway.ContentAccessService"                     

   2:               behaviorConfiguration="ABC.ServiceHost.ServiceBehavior">                    

   3:        <host>                    

   4:          <baseAddresses>                    

   5:            <add baseAddress = "net.pipe://localhost/" />                    

   6:          </baseAddresses>                    

   7:        </host>                    

   8:        <endpoint address="ContectAccessService"

   9:                    

  10:                  binding="netNamedPipeBinding"

  11:                  bindingConfiguration="NetPipeBinding_IContectAccessService"

  12:                  contract="ABC.Service.AuthenticationGateway.IContectAccessService" />

  13:                    

  14:        <endpoint address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" /> 

  15: </service>

Now, here relative address is ContectAccessService. So, my absolute url would be net.pipe://ABC/Service1.svc/ContectAccessSerice.

This is the browse the url for svc file in the url, you can see the wsdl for the service. Mine address was http://localhost:62/Service1.svc?wsdl. Mine, Website was hosted on 62 port.

Doing that, I need to test my Namedpipe service. I was using WCFTestClient, which is under C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE. Replace yellow part which wherever you have installed Visual Studio. 10.0 would be replaced by version for 2010/2012/2013. For VS 2010, it’s 10.0.

I was trying to address in pink in WcfTestClient.exe add service dialog

Doing so, I use to get the error

Error: Cannot obtain Metadata from net.pipe://ABC/Service1.svc/ContectAccessService If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: net.pipe://ABC/Service1.svc/ContectAccessService Metadata contains a reference that cannot be resolved: ‘ net.pipe://ABC/Service1.svc/ContectAccessService ‘. <?xml version=”1.0″ encoding=”utf-16″?><Fault xmlns=”http://www.w3.org/2003/05/soap-envelope”><Code><Value>Sender</Value><Subcode><Value xmlns:a=”http://www.w3.org/2005/08/addressing”>a:ActionNotSupported</Value></Subcode></Code><Reason><Text xml:lang=”en-US”>The message with Action ‘http://schemas.xmlsoap.org/ws/2004/09/transfer/Get&#8217; cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</Text></Reason></Fault>

I was baffled and perplex by the error. There is already, mex binding expose, then, why isn’t the ‘WCF client’ can’t get the metaexchange data?

It found, that error was silly from my side. The address which need to input in WCF Test Client was net.pipe://ABC/Service.svc     instead of

net.pipe://ABC/Service1.svc/ContectAccessSerice.

What’s Does IIS NamedPipe Binding Information means

IIS Binding Information

While troubleshooting for one of the application, I was struck at what does IIS Binding Information means when add NamedPipe binding to IIS Website.

This is an old question, but I figured I’d add my answer since I also needed an answer for this (and maybe there are others out there who need it too).The base address of an IIS-hosted WCF service is controlled by IIS and cannot be overridden in web.config.  Instead, you can control the base addresses by updating the IIS site binding information for the site you’re hosting your service in.

Most of the documentation I found online suggests using * as the binding configuration for net.pipe. But if you instead use “virtualsite.com” as the binding configuration value, the base address of your net.pipe endpoint will be “virtualsite.com” rather than the machine name.

Here is an example using appcmd to configure a site in IIS with the correct net.pipe binding:

%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.pipe',bindingInformation='virtualhostname.com']

One note about HostnameComparisonMode, it has no effect in IIS according to MSDN:

These values have no effect when used inside of the Internet Information Services (IIS) or Windows Process Activation Service (WAS) hosting environment. In those cases, WCF uses whatever hostname comparison mode is provided by the IIS Web Site hosting the WCF services.

Instead, you have to use the mechanism I described above. I figured this out by investigating how hostname binding works in HTTP for IIS. Unfortunately, I’ve not been able to find any official documentation for this IIS-based scenario for other WCF transports.