WCF - Consuming WCF Service
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:
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2014-07-08 AcceptAsync和BeginAccept的区别