WCF is called minimal channel example

I am looking for a minimal example of WCF Named Pipes (I expect two minimal applications, a server and a client, that can communicate through a named pipe.)

Microsoft has a Getting Started article > that describes WCF over HTTP, and I'm looking for something similar about WCF and named pipes.

I found several posts on the Internet, but they are a bit "advanced". I need something minimal, only required functionality, so I can add my code and make the application work.

How to replace this with using a named pipe?

<endpoint address="http://localhost:8000/ServiceModelSamples/Service/CalculatorService" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator" contract="ICalculator" name="WSHttpBinding_ICalculator"> <identity> <userPrincipalName value="OlegPc\Oleg" /> </identity> </endpoint> 

How to replace this with using a named pipe?

 // Step 1 of the address configuration procedure: Create a URI to serve as the base address. Uri baseAddress = new Uri("http://localhost:8000/ServiceModelSamples/Service"); // Step 2 of the hosting procedure: Create ServiceHost ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress); try { // Step 3 of the hosting procedure: Add a service endpoint. selfHost.AddServiceEndpoint( typeof(ICalculator), new WSHttpBinding(), "CalculatorService"); // Step 4 of the hosting procedure: Enable metadata exchange. ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; selfHost.Description.Behaviors.Add(smb); // Step 5 of the hosting procedure: Start (and then stop) the service. selfHost.Open(); Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. selfHost.Close(); } catch (CommunicationException ce) { Console.WriteLine("An exception occurred: {0}", ce.Message); selfHost.Abort(); } 

How to create a client to use a named pipe?

+84
c # named-pipes wcf
Sep 08 '11 at 19:52
source share
4 answers

I just found this great little tutorial . Invalid link ( Cached version )

I also followed the Microsoft tutorial, which is good, but I only need pipes.

As you can see, you do not need configuration files and all these messy things.

By the way, it uses both HTTP and pipes. Just remove all lines of code related to HTTP and you get an example of a clean pipe.

+73
Oct. 20 '11 at 8:00
source share

Try it.

Here is the service part.

 [ServiceContract] public interface IService { [OperationContract] void HelloWorld(); } public class Service : IService { public void HelloWorld() { //Hello World } } 

Here is the proxy

 public class ServiceProxy : ClientBase<IService> { public ServiceProxy() : base(new ServiceEndpoint(ContractDescription.GetContract(typeof(IService)), new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/MyAppNameThatNobodyElseWillUse/helloservice"))) { } public void InvokeHelloWorld() { Channel.HelloWorld(); } } 

And here is part of the hosting service.

 var serviceHost = new ServiceHost (typeof(Service), new Uri[] { new Uri("net.pipe://localhost/MyAppNameThatNobodyElseWillUse") }); serviceHost.AddServiceEndpoint(typeof(IService), new NetNamedPipeBinding(), "helloservice"); serviceHost.Open(); Console.WriteLine("Service started. Available in following endpoints"); foreach (var serviceEndpoint in serviceHost.Description.Endpoints) { Console.WriteLine(serviceEndpoint.ListenUri.AbsoluteUri); } 
+50
Oct 20 2018-11-11T00:
source share

Check out my very simplified Echo example : It is designed to use basic HTTP communication, but it can be easily changed to use named pipes by editing the app.config files for the client and server. Make the following changes:

Edit the app.config file by deleting or commenting out the http baseAddress entry and adding a new baseAddress for the named pipe (called net.pipe ). In addition, if you are not going to use HTTP for the communication protocol, make sure that serviceMetadata strong> and serviceDebug are either commented out or deleted:

 <configuration> <system.serviceModel> <services> <service name="com.aschneider.examples.wcf.services.EchoService"> <host> <baseAddresses> <add baseAddress="net.pipe://localhost/EchoService"/> </baseAddresses> </host> </service> </services> <behaviors> <serviceBehaviors></serviceBehaviors> </behaviors> </system.serviceModel> </configuration> 

Edit the app.config file so that basicHttpBinding is either commented out or deleted, and netNamedPipeBinding . You will also need to modify the endpoint entry to use the channel:

 <configuration> <system.serviceModel> <bindings> <netNamedPipeBinding> <binding name="NetNamedPipeBinding_IEchoService"/> </netNamedPipeBinding> </bindings> <client> <endpoint address = "net.pipe://localhost/EchoService" binding = "netNamedPipeBinding" bindingConfiguration = "NetNamedPipeBinding_IEchoService" contract = "EchoServiceReference.IEchoService" name = "NetNamedPipeBinding_IEchoService"/> </client> </system.serviceModel> </configuration> 

The above example will only work with named pipes, but nothing prevents you from using multiple protocols to start your service. AFAIK, you should be able to run the service on the server using both named pipes and HTTP (as well as other protocols).

In addition, the binding in the client's app.config file is very simplified. There are many different options that you can configure, in addition to specifying baseAddress ...

+11
Jan 09 2018-12-12T00:
source share

I created this simple example from various search results on the Internet.

 public static ServiceHost CreateServiceHost(Type serviceInterface, Type implementation) { //Create base address string baseAddress = "net.pipe://localhost/MyService"; ServiceHost serviceHost = new ServiceHost(implementation, new Uri(baseAddress)); //Net named pipe NetNamedPipeBinding binding = new NetNamedPipeBinding { MaxReceivedMessageSize = 2147483647 }; serviceHost.AddServiceEndpoint(serviceInterface, binding, baseAddress); //MEX - Meta data exchange ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); serviceHost.Description.Behaviors.Add(behavior); serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(), baseAddress + "/mex/"); return serviceHost; } 

Using the above URI, I can add the link in my client to the web service.

0
Sep 05 '17 at 7:14
source share



All Articles