消費WCF服務託管在IIS5/6

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

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

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

Consuming WCF hosted in IIS

 

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

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

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

Consuming WCF hosted in IIS

 

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

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

Consuming WCF hosted in IIS

 

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 WCF hosted in IIS

上一篇: 消費WCF服務 下一篇: 自託管消費WCF服務