Home > Backend Development > C++ > How to Create a Minimal WCF Named Pipe Application?

How to Create a Minimal WCF Named Pipe Application?

Susan Sarandon
Release: 2025-01-04 17:04:40
Original
656 people have browsed it

How to Create a Minimal WCF Named Pipe Application?

WCF Named Pipes Minimal Example

Introduction:

Communication via named pipes is a fundamental aspect of WCF applications. This article aims to provide a simplified guide for setting up a minimal WCF named pipe-based implementation, addressing common questions related to server and client configuration.

Named Pipe Endpoint Configuration:

To configure a named pipe endpoint, replace the HTTP address with the following:

<endpoint address="net.pipe://localhost/namedpipe"
    binding="netNamedPipeBinding" contract="ICalculator" name="NetNamedPipeBinding_ICalculator">
</endpoint>
Copy after login

Service Hosting:

For service hosting:

// Create a URI with the named pipe address.
Uri baseAddress = new Uri("net.pipe://localhost/namedpipe");

// Create a ServiceHost for the CalculatorService.
ServiceHost selfHost = new ServiceHost(typeof(CalculatorService), baseAddress);

try
{
    // Add the named pipe service endpoint.
    selfHost.AddServiceEndpoint(typeof(ICalculator), new NetNamedPipeBinding(), "");

    // Start the service.
    selfHost.Open();
}
catch (CommunicationException ce)
{
    Console.WriteLine("Exception occurred: {0}", ce.Message);
    selfHost.Abort();
}
Copy after login

Client Generation:

For client generation:

// Create a channel factory for the named pipe endpoint.
ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>("NetNamedPipeBinding_ICalculator");

// Create a client proxy.
ICalculator client = factory.CreateChannel();
Copy after login

The above is the detailed content of How to Create a Minimal WCF Named Pipe Application?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template