Web application developer

WCF service with Named Pipes

wcf named pipes

Written by: willem | Nov 6 2014 1:54 PM

The nice thing of WCF is that you can easily switch connection methods. the only thing you need to change is some configuration and the type of the connection classes you’re using. All other code remains the same.

If you use named pipes for your WCF service you’re sharing memory between server and client. This is of course a very fast method, but the downside is that both the client and the server need to be running on the same machine.

This blog post is one in a series of posts.

If you followed previous post you will see creating a service that runs on named pipes works the same a configuring your service for TCP. There are three steps to follow:

  • configure IIS
  • change web.config
  • change connection classes in the client

If you didn’t follow the previous blog strictly, you might not have installed the named pipes software for WCF. Check this in “turn windows features on or off” and install it if necessary.

001

You also might want to download the project code from the previous post. It's here.

Now, start up the IIS manager and select the wcf service on the left pane and click “bindings” on the right pane.

001

Click add.

002

Select the net.pipe option and put * in the text field.

003

Click “OK” and “Close”.

Now Click “Advanced Settings” in the right pane of IIS manager.

004

Add “net.pipe” to the enabled protocols

005

Click “OK” and close the IIS Manager.

Open the web.config file in the publish folder. Make sure you do not accidentally open the web.config in the project folder since that won’t work here.

Add a binding in system.servicemodel –> bindings

	<netNamedPipeBinding>
	     <binding name="InsecNamedPipe">
	          <security mode="None"></security>
	    </binding>
	</netNamedPipeBinding>

And add an endpoint.

	<endpoint address="net.pipe://localhost/messageservice.messageservice.svc" binding="netNamedPipeBinding" bindingConfiguration="InsecNamedPipe" contract="MessageService.IMessageService"></endpoint>

Save the config file.

Now open the project in visual studio. Since we are only using the client application you can unload MessageService project (but not necessary).

Change the button_click method in MainWindow.xaml.cs into this:

	private void Button_Click(object sender, RoutedEventArgs e)
	{
	     EndpointAddress endpoint = new EndpointAddress("net.pipe://localhost/MessageService.MessageService.svc");
	     NetNamedPipeBinding binding = new NetNamedPipeBinding();
	     binding.Security.Mode = NetNamedPipeSecurityMode.None;
	     ChannelFactory<IMessageService> factory = new ChannelFactory<IMessageService>(binding, endpoint);
	     IMessageService service = factory.CreateChannel();

	     MessageService.Message message = new MessageService.Message();
	    message.Reverse = true;
	    message.StringValue = InputTextBox.Text;

	    OutputTextBox.Text = service.ProcessMessage(message);
	}

Here only three changes are made:

  • The endpoint address is changed (including the protocol!).
  • The binding class is changed to NetNamedPipeBinding.
  • The security mode in set to none since we don’t use security here.

Now run the client project and send some text to process!

006

Download the project here.

No Comments

Add a Comment

About Me

I'm a web application developer specializing in asp.net. I have skills in asp.net, C#, html5, javascript, asp.net mvc, design patterns and more.

more about me

Random background module

This module for Orchard CMS lets you upload a list of images. For every page it chooses one randomly and sets it a the background image.

Go to project page on CodePlex
Download module

The Monack Framework

This open source framework makes it easy to build and develiver custom web applications. Unfortunately I can't spent much time on it so it is still work in progress. 

More about MonackFr
Project page at CodePlex

Orchard

Since I decided to create this website in Orchard and didn't know anything about
it when I started, I also post my experiences with this CMS.