消費WCF服務託管在IIS5/6

在IIS中承載5/6 WCF服務的消費過程下面詳細包括創建代理和控制檯應用程序進行了討論。

第1步:一旦服務託管在IIS中,接下來我們要創建消費這種服務的客戶端應用程序。在創建客戶端應用程序,我們需要創建代理的服務。這個代理所使用的客戶端應用程序與服務進行交互。要創建代理,運行Visual Studio 2008命令提示。使用服務工具,我們可以創建代理類和它的配置信息。

svcutil http://localhost/IISHostedService/Service.svc

Consuming

執行此命令後,我們會發現在默認位置生成了兩個文件。

  • MyService.cs - 代理類的WCF服務
  • output.config - 有關該服務的配置信息。

第2步:現在,我們將開始創建使用Visual Studio 2008(客戶端應用)的控制檯應用程序。

Consuming

第3步:添加引用「System.ServiceModel」;這是WCF的核心DLL。

第4步:創建一個代理類。

Consuming

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyServiceClient { Class Program { Static void Main(string[] args) { //Creating Proxy for the MyService ServiceClient Client = newServiceClient(); Console.WriteLine("Client calling the service..."); Console.WriteLine("Hello Ram"); Console.Read(); } } }

Consuming