WCF named pipe minimal example
I just found this excellent little tutorial. broken link (Cached version)
I also followed Microsoft's tutorial which is nice, but I only needed pipes as well.
As you can see, you don't need configuration files and all that messy stuff.
By the way, he uses both HTTP and pipes. Just remove all code lines related to HTTP, and you'll get a pure pipe example.
WCF Named Pipe in Windows Service using App.Config
<endpoint address="net.pipe://localhost/MyIpcAppToService" binding="wsDualHttpBinding" bindingConfiguration="MyAppToServiceEndpointBinding" contract="MyIpc.IIpcAppToService"/>
Make sure that the service address is in the same form (transport protocol) as the binding type.
- TCP(net.tcp://localhost:8000/myservice) NetTcpBinding
- IPC(net.pipe://localhost/mypipe) NetNamedPipeBinding
Http/Https(http://localhost:8000/myservice)
Wshttpbinding,Wsdualhttpbinding,basichttpbindingWebSocket(ws://localhost:3434) Nethttpbinding
MSMQ(net.msmq://localhost/private/myservice) NetMsmqBinding
we are supposed to use NetnamedPipeBinding for the service address. Please refer to my example.
Updated
I have a wcf service using NetNamedPipeBinding hosted in IIS, wish it is useful to you.
Server(wcf service application)
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
Web.config(Server side)
<system.serviceModel>
<services>
<service behaviorConfiguration="BehaviorMyService" name="WcfService1.Service1">
<endpoint address="MyIpcAppToService"
binding="netNamedPipeBinding"
bindingConfiguration="EndpointBindingMyAppToService"
contract="WcfService1.IService1"
/>
<endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BehaviorMyService">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netNamedPipeBinding>
<binding name="EndpointBindingMyAppToService"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00"
transactionFlow="false"
transferMode="Buffered"
transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288"
maxConnections="10"
maxReceivedMessageSize="2147483647"
>
<security mode="None">
<transport protectionLevel="None" />
</security>
</binding>
</netNamedPipeBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
</system.serviceModel>
Enable WCF new feature.
IIS site(enable net.pipe)
Client(console application)
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
var result = client.GetData(34);
Console.WriteLine(result);
Client app.config(auto-generated)
I use the http address(service metadata GET address http://localhost:8733/Service1.svc?wsdl) to generated the configuration.
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="NetNamedPipeBinding_IService1">
<security mode="None" />
</binding>
</netNamedPipeBinding>
</bindings>
<client>
<endpoint address="net.pipe://mynetpipe/Service1.svc/MyIpcAppToService"
binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IService1"
contract="ServiceReference1.IService1" name="NetNamedPipeBinding_IService1" />
</client>
</system.serviceModel>
Feel free to let me know if there is anything I can help with.
WCF with named pipes: how to allow parallel calls?
OK, I've solved this: first of all I was missing the following attribute on my contract implementation class:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
public class CommandReceiver : ICommandReceiver
{
public string Foo()
{
//Do stuffs
System.Threading.Thread.Sleep(3000);
return "FOO";
}
public string Bar()
{
//Do stuffs
System.Threading.Thread.Sleep(3000);
return "BAR";
}
}
And then I've discovered that the service works perfectly, but not while debugging in visual studio. Releasing and installing it on the system solved the issue.
WCF NetNamedPipeBinding - Same pipe name and different users
A base address can only be used by one application on a computer.
But if different users log in to the same Windows Server, each user will encounter a unique Windows computing session. You can think of each user logging in to their own computer, and these users will not interfere with each other.
For more information about "MultiPoint Services", you can refer to this link.
WCF Named Pipe IPC
For (1) and (2) the answer is simple: You can ask WCF to use a singleton instance of your service to handle all requests. Mostly all you need to do is use the alternate ServiceHost constructor that takes an Object instance instead of a type.
Notice, however, that you'll be responsible for making your service class thread safe.
As for 3, it really depends a lot on what you need to do, your performance needs, how many clients you expect at the same time, the amount of data you'll be moving and for how long it needs to be available, etc.
How to make a WCF named pipe address equal to a WinApi one?
There is no documented way of doing that. After a few tests I came to the following conclusions:
If you have a WCF server and a Win32 C++ client, the last one will see the first one address as a UUID in the following format:
12345678-1234-1234-1234-123456789abc
And this UUID seems random, since it changes for the same WCF address every time the server is started.
I don't know if a Win32 C++ named pipe server with a GUID format address will be visible from a WCF client, but I'm sure that if it does, the server will have to implement the poorly documented protocol used by WCF.
The documentation for such protocol is provided as an answer to my previous question on this subject.
EDIT Further research revealed that the pipe address is stored in the FileMapping. This entry address in its turn is a base64 encoded hash of a normalized version of the NetNamedPipe address.
Expose a WCF Service through a Named Pipes binding
Your endpoint looks fine, although I'm curious about what's in localBinding...
Sounds like the easiest option is to just change the endpoint configuration on the named pipes client to match your service endpoint. The client shouldn't care as long as it's the only endpoint in the clients config file. Otherwise you'll have to add names to your endpoints and have the client pick a specific one when you new-up the proxy object.
Good luck!
Related Topics
C# SQL Server - Passing a List to a Stored Procedure
Testing If Object Is of Generic Type in C#
How to Send Emails Through Ssl Smtp with the .Net Framework
Casting a Variable Using a Type Variable
Writing Large Number of Records (Bulk Insert) to Access in .Net/C#
Transparent Background Image for Form - Smooth Edge Shape for the Form
Validate Image from File in C#
Execute Multiple Command Lines with the Same Process Using .Net
Blazor - Display Wait or Spinner on API Call
An Implementation of the Fast Fourier Transform (Fft) in C#
Is Using a 'Goto' Statement Bad
How to Run Another Application Within a Panel of My C# Program
How to Rotate a Picture in Winforms
How To: Best Way to Draw Table in Console App (C#)
How to Set Session Timeout in Web.Config
Should I Use Public Properties and Private Fields or Public Fields for Data