WCF - Consuming WCF Service

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:

时间: 2024-10-10 06:24:48

WCF - Consuming WCF Service的相关文章

WCF注册Windows Service

WCF注册Windows Service 2014-06-14 返回 在前面创建一个简单的WCF程序,我们把WCF的服务寄宿到了Host这个控制台项目中了.下面将介绍如何把WCF的服务寄宿到Windows服务中: 1. 删除原来Host控制台项目,然后在solution上右键,新建一个WindowService项目.如下图: 2.对MyFirstWindowsService项目添加对Contracts项目.Service项目和System.ServiceModel的引用. 3.将MyFristW

跟我一起学WCF(13)——WCF系列总结

引言 WCF是微软为了实现SOA的框架,它是对微乳之前多种分布式技术的继承和扩展,这些技术包括Enterprise Service..NET Remoting.XML Web Service.MSMQ等.WCF推出的原因在于:微软想将不同的分布式技术整合起来,提供一个统一的编程模型,这样对于开发者来说绝对是好事.在过去的2个月时间内,我陆续写了WCF系列文章,这些文章只是自己这段时间学习WCF内容的一个学习过程和笔记,希望通过这种写博文的方式记录下来和总结.本系列并没有对WCF机制做一个深入解析

Detecting Client Connection in WCF Long Running Service (Heartbeat Implementation) z

Download source - 45.3 KB Introduction Hello everyone! This is my first blog on WCF and I hope that you like it. Today, I will talk about how to implement heart beat mechanism in WCF, so that whenever client is not alive, our WCF service detects it a

WCF - Versus Web Service

There are some major differences that exist between WCF and a Web service which are listed below. 这里总结了WCF和网络服务之间主要的不同之处 Attributes - WCF service is defined by ServiceContract and OperationContract attributes, whereas a web service is defined by WebS

扩展Wcf call security service, 手动添加 Soap Security Head.

有次我们有个项目需要Call 一个 Java 的 web service, Soap包中需要一个 Security Head <soapenv:Header> <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <w

在IIS8.5的环境下配置WCF的Restful Service

今天在客户的环境中(Windows Server 2012 R2 + IIS 8.5)搭建Call WCF Restful Service的功能,发现了几个环境配置的问题,记录如下: 1):此环境先安装了.Net Framework,后安装的IIS,导致IIS site上无法运行.Net的程序, 因此我们要向IIS中注册.Net Framework,具体操作请参考如下链接: http://www.cnblogs.com/mingmingruyuedlut/archive/2011/11/04/2

使用WCF 创建 Rest service

REST SERVICE 允许客户端修改url路径,并且web端功过url 请求数据. 他使用http协议进行通讯,想必大家都知道 . 并且我们可以通过设置进行数据类型转换, 支持XML,JSON 格式. 大多情况下我们都采用webservice ,或在MVC下创建REST服务来支持服务端调用. 但WCF当道之时.我们是否想过我们还有一大把的wcf服务想采用REST json格式来进行手机模块接口调用呢? 下面介绍通过WCF创建REST serveic ,你无需改变原有服务处理,只需要添加一些配

WCF宿主Window Service Demo

尝试了下将服务寄宿在window 服务上.具体步骤如下 整个解决方案截图 一.创建window 服务 Wcf.WinService namespace Wcf.WinService { public partial class CalService : ServiceBase { public ServiceHost serviceHost = null; //服务宿主 public CalService() { InitializeComponent(); base.ServiceName =

WCF - Hosting WCF Service

After creating a WCF service, the next step is to host it so that the client applications can consume it. This is known as WCF service hosting. A WCF service can be hosted by using any of the four ways given below: 在创建wcf服务后,下一个步骤就是托管该服务,确保客户端应用可以使用它