消费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服务