WCF - Consuming WCF Service

本文详细介绍了如何在IIS5/6中消费WCF服务,包括创建代理类和服务配置文件的过程,并提供了步骤指导,帮助读者理解如何从客户端应用程序访问WCF服务。

https://www.tutorialspoint.com/wcf/wcf_consuming_service.htm

WCF services allow other applications to access or consume them. A WCF service can be consumed by many ways depending on the hosting type. Here, we are explaining the step-by-step method to consume a WCF service for each of the following popular hosting options:

  • Consuming WCF Service hosted in IIS 5/6
  • Consuming WCF Service that is self-hosted
  • Consuming WCF Service hosted in Windows Activation Service
  • Consuming WCF Service hosted in Windows Service

Consuming WCF Service Hosted in IIS 5/6

The process of consumption of a WCF service hosted in IIS 5/6 is discussed below in detail. In addition, the discussion includes how to create proxy and console applications.

Step-1: Once a service is hosted in IIS, we have to consume it in client applications. Before creating the client application, we need to create a proxy for the service.

This proxy is used by the client application to interact with the service. To create a proxy, run Visual Studio 2008 command prompt.

Using service utility, we can create the proxy class and its configuration information.

svcutilhttp://localhost/IISHostedService/Service.svc

 

After executing this command, we will get two files generated in the default location.

  • MyService.cs – Proxy class for the WCF service

  • output.config – Configuration information about the service

Step-2: Now, we will start creating the Console application using Visual Studio 2008 (Client application).

 

Step-3: Add the reference 'System.ServiceModel'; this is the core dll for WCF.

Step-4: Create a Proxy class.

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();
      }
   }
}

The output appears as follows:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值