WCF 命名管道最小範例
簡介:
透過命名管道進行通訊為基礎WCF 應用程式的一個面向。本文旨在為設定基於命名管道的最小 WCF 實作提供簡化指南,解決與伺服器和用戶端配置相關的常見問題。
命名管道端點設定:
要設定命名管道端點,請將 HTTP地址替換為以下內容:
<endpoint address="net.pipe://localhost/namedpipe" binding="netNamedPipeBinding" contract="ICalculator" name="NetNamedPipeBinding_ICalculator"> </endpoint>
Service寄存:
對於服務託管:
// 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(); }
客戶端產生:
對於客戶端產生:
// 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();
以上是如何建立最小的 WCF 命名管道應用程式?的詳細內容。更多資訊請關注PHP中文網其他相關文章!