WCF 命名管道最小示例 [英] WCF named pipe minimal example

查看:40
本文介绍了WCF 命名管道最小示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找 WCF 命名管道的最小示例(我希望有两个最小的应用程序,服务器和客户端,它们可以通过命名管道进行通信.)

I'm looking for minimal example of WCF Named Pipes (I expect two minimal applications, server and client, which can communicate via a named pipe.)

Microsoft 有一篇精彩的文章 入门教程 描述了WCF 通过 HTTP,我正在寻找与 WCF 和命名管道类似的东西.

Microsoft has the briliant article Getting Started Tutorial that describes WCF via HTTP, and I'm looking for something similar about WCF and named pipes.

我在网上找了几篇帖子,但都有些高级".我需要一些最小的,只有强制性的功能,所以我可以添加我的代码并使应用程序运行.

I've found several posts in the Internet, but they are a little bit "advanced". I need something minimal, only mandatory functionality, so I can add my code and get the application working.

如何替换它以使用命名管道?

How do I replace that to use a named pipe?

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

如何替换它以使用命名管道?

How do I replace that to use 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 do I generate a client to use a named pipe?

推荐答案

我刚发现 这个优秀的小教程. 断开的链接 (缓存版本)

我也遵循了微软的教程,这很好,但我也只需要管道.

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.

顺便说一下,他同时使用 HTTP 和管道.只需删除所有与 HTTP 相关的代码行,您就会得到一个纯管道示例.

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 命名管道最小示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆