WCF客户端代理
- 创建类库WCFServiceProxy
- 添加System.ServiceModel、WCFService(见上篇文章)引用
- 创建类:BookServiceClient
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.ServiceModel;
- using System.ServiceModel.Channels;
- using System.Text;
- using System.Threading.Tasks;
- using WCFService;
- using WCFService.Models;
- namespace WCFServiceProxy
- {
- public class BookServiceClient : ClientBase<IBookService>, IBookService
- {
- public BookServiceClient() : base() { }
- public BookServiceClient(string endpointConfigurationName) : base(endpointConfigurationName) { }
- public BookServiceClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { }
- public BookServiceClient(string endpointConfigurationName, EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress) { }
- public BookServiceClient(Binding binding, EndpointAddress remoteAddress) : base(binding, remoteAddress) { }
- public bool Add(string name, double price)
- {
- return base.Channel.Add(name, price);
- }
- public List<Book> GetList()
- {
- return base.Channel.GetList();
- }
- }
- }
创建类BookServiceProxy
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.ServiceModel;
- using System.Text;
- using System.Threading.Tasks;
- using WCFService.Models;
- namespace WCFServiceProxy
- {
- public static class BookServiceProxy
- {
- private static string _clientEndpointName = "bookInfo";
- static List<Book> list = new List<Book>();
- public static bool Add(string name, double price)
- {
- BookServiceClient client = null;
- try
- {
- client = new BookServiceClient(_clientEndpointName);
- client.Add(name, price);
- client.Close();
- return true;
- }
- catch (Exception ex)
- {
- if (client != null && client.State != CommunicationState.Closed)
- {
- client.Abort();
- client = null;
- }
- return false;
- }
- finally
- {
- client = null;
- }
- }
- public static List<Book> GetList()
- {
- BookServiceClient client = null;
- try
- {
- client = new BookServiceClient(_clientEndpointName);
- list = client.GetList();
- client.Close();
- return list;
- }
- catch (Exception ex)
- {
- if (client != null && client.State != CommunicationState.Closed)
- {
- client.Abort();
- client = null;
- }
- return null;
- }
- finally
- {
- client = null;
- }
- }
- }
- }
WCF客户端代理的更多相关文章
- 终于解决:升级至.NET 4.6.1后VS2015生成WCF客户端代理类的问题
在Visual Studio 2015中将一个包含WCF引用的项目的targetFramework从4.5改为4.6.1的时候,VS2015会重新生成WCF客户端代理类.如果WCF引用配置中选中了&q ...
- WCF 客户端代理生成 通过SvcUtil.exe
WCF服务调用通过两种常用的方式:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式,一种是通过ChannelFactory直接创建服务代理对象进行服务调用. 下面简单说下如何通过Sv ...
- 通过SvcUtil.exe 生成 Wcf 客户端代理
WCF服务调用通过两种常用的方式:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式,一种是通过ChannelFactory直接创建服务代理对象进行服务调用. SvcUtil.exe ...
- WCF生成客户端代理对象的两种方法的解释
最近在封装WCF,有一些很好的实践就记录下来,大家可以放心使用,所有代码都已经调试过.如果有高手可以大家探讨一下. 在WCF中有两种不同的方法可以用于创建客户端服务对象,他们分别为: 1. 代理构造法 ...
- wcf生成客户端代理类步骤及语句
通过svcutil.exe工具生成客户端代理类和客户端的配置文件 .在运行中输入cmd打开命令行 ()cd C:\Program Files (x86)\Microsoft SDKs\Windows\ ...
- wcf http 代理
两个我都还没试,先记录着,其实我也不咋懂,所以记录着,权当一个线索 第一种 wcf中设置代理是在bing类中设置的,比如 WSHttpBinding ws = new WSHttpBinding(); ...
- WCF初探-10:WCF客户端调用服务
创建WCF 服务客户端应用程序需要执行下列步骤: 获取服务终结点的服务协定.绑定以及地址信息 使用该信息创建 WCF 客户端 调用操作 关闭该 WCF 客户端对象 WCF客户端调用服务存在以下特点: ...
- WCF初探-11:WCF客户端异步调用服务
前言: 在上一篇WCF初探-10:WCF客户端调用服务 中,我详细介绍了WCF客户端调用服务的方法,但是,这些操作都是同步进行的.有时我们需要长时间处理应用程序并得到返回结果,但又不想影响程序后面代码 ...
- 【WCF系列】(四)WCF客户端怎么消费服务
WCF客户端怎么消费服务 获取服务绑定协议.绑定和地址:实现方式 SvcUtil方式:SvcUtil.exe是一个命令行工具,位于:C:\Program Files (x86)\Microsoft S ...
随机推荐
- CSS 定位详解
CSS 有两个最重要的基本属性,前端开发必须掌握:display 和 position position 属性的作用 position属性用来指定一个元素在网页上的位置,一共有5种定位方式,即posi ...
- vue2.0 + element-ui2实现分页
当我们向服务端请求大量数据的时候,并要在页面展示出来,怎么办?这个时候一定会用到分页. 本次所使用的是vue2.0+element-ui2.12实现一个分页功能,element-ui这个组件特别丰富, ...
- Xhorse Condor XC-Mini Plus回顾
Condor是Xhorse生产的最新型电子钥匙切割机.该机器在激光,圆柱和Tibbe键上具有出色的切割性能,几乎可以复制,切割,编码和解码任何汽车钥匙! Condor XC-MINI Plus的亮点: ...
- IDEA运行有问题debug正常解决方案
朋友们!有没有遇到这样的问题,IDEA运行有问题,debug确是正常的,不经怀疑人生! 不要慌!点击maven,clean一下,再compile一下,就好啦! 不要慌!点击maven,clean一下, ...
- [Python之路] 元类(引申 单例模式)
一.类也是对象 当我们定义一个变量或者函数的时候,我们可以在globals()的返回值字典中找到响应的映射: def A(): print("This is function A" ...
- 洛谷 P1341 无序字母对(欧拉路)
P1341 无序字母对 题目提供者yeszy 标签 福建省历届夏令营 难度 提高+/省选- 最新讨论 题目描述 给定n个各不相同的无序字母对(区分大小写,无序即字母对中的两个字母可以位置颠倒).请构造 ...
- 【CUDA 基础】0.0 腾讯云CUDA环境搭建
title: [CUDA 基础]0.0 腾讯云CUDA环境搭建 categories: CUDA Freshman tags: CUDA 环境搭建 toc: true date: 2018-02-13 ...
- EasySwoole 在mac上装虚拟机centos共享mac目录报错处理
[2019-09-26 21:37:09][DEBUG][ERROR] : [listen /media/psf/Home/wwwroot/myobj/easyswoole/Temp/TaskWork ...
- TCP->IP输出 之 ip_queue_xmit、ip_build_and_send_pkt、ip_send_unicast_reply
概述 ip_queue_xmit是ip层提供给tcp层发送回调,大多数tcp发送都会使用这个回调,tcp层使用tcp_transmit_skb封装了tcp头之后,调用该函数,该函数提供了路由查找校验. ...
- TCP之11种状态变迁
1. TCP 之11种状态变迁 TCP 为一个连接定义了 11 种状态,并且 TCP 规则规定如何基于当前状态及在该状态下所接收的分节从一个状态转换到另一个状态.如,当某个应用进程在 CLOSED 状 ...