WCF扩展之实现ZeroMQ绑定和protocolBuffer消息编码(一)概要设计
- 客户端调用的方式是一致的
- 服务端处理请求的方式是一致的
- 服务的实例管理的方式是一致的
- 设计服务的操作模式的方式是一致的
- 如果将自定义数据作为服务的参数,数据的定义是一致的
- 处理异常的方式是一致的
- 如果连接的通信技术支持事物,事物的处理是一致的
WCF可以隔离业务层和技术层,体现在:
- 当客户端调用服务时,可以不需要知道服务端的实现语言和平台
- 当服务端处理请求时,可以不需要知道客户端的实现语言和平台
- 实现WCF的服务端时,只需要考虑业务接口的实现,另外接口和方法添加少量的属性、在配置中添加服务的地址
- 实现WCF的客户端时,只需要按照协议调用服务,另外在配置中添加服务的地址






虽然ZMQBinding和ProtocolBufferMessageExtension的做了很多转换工作,但是一旦将它们注册到WCF中,应用开发人员的工作量很小。
- 当把WCF作为服务端,ZMQ作为客户端时,WCF服务端需要如下步骤:
[ServiceContract]
public interface IService1
{
[OperationContract]
string UpdatePatients(WCF_Client_ZMQBinding.iStationMovementPos move);
}
public class Service1 : IService1
{
public string UpdatePatients(WCF_Client_ZMQBinding.iStationMovementPos move)
{
return "wcf response";
}
}
自定义数据编码是采用了反射的方式,把iStationMovementPos转成protocolBuffer的可序列化的类类型。
public class iStationMovementPos
{
public int IhMaxPos{get;set;}
public int IhPos {get;set;}
public int IhMinPos{get;set;} public int IvMaxPos{get;set;}
public int IvPos {get;set;}
public int IvMinPos{get;set;} public int IaMaxPos{get;set;}
public int IaPos {get;set;}
public int IaMinPos{get;set;} public bool LaserStatus {get;set;}
public int CouchMarkPos { get; set; }
}
ServiceHost host = new ServiceHost(typeof(Service1));
host.Open();
- 当把ZMQ作为服务端,WCF作为客户端时,WCF客户端需要如下步骤:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName = "ServiceReference1.IService1")]
public interface IService1
{ [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/DoWork", ReplyAction = "http://tempuri.org/IService1/DoWorkResponse")]
[ProtocolBufferMessageExtension.Formatter.PBFormatMessage]
string DoWork(iStationMovementPos move); [System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IService1/DoWork", ReplyAction = "http://tempuri.org/IService1/DoWorkResponse")]
System.Threading.Tasks.Task<string> DoWorkAsync(iStationMovementPos move);
} [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IService1Channel : Client.ServiceReference1.IService1, System.ServiceModel.IClientChannel
{
} [System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class Service1Client : System.ServiceModel.ClientBase<Client.ServiceReference1.IService1>, Client.ServiceReference1.IService1
{ public Service1Client()
{
} public Service1Client(string endpointConfigurationName) :
base(endpointConfigurationName)
{
} public Service1Client(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
} public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
} public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public string DoWork(iStationMovementPos move)
{
return base.Channel.DoWork(move);
}
public System.Threading.Tasks.Task<string> DoWorkAsync(iStationMovementPos move)
{
return base.Channel.DoWorkAsync(move);
}
}
iStationMovementPos move = new iStationMovementPos()
{
IhMaxPos = ,
IhMinPos = ,
IaPos = ,
IaMaxPos = ,
IaMinPos = ,
IhPos = ,
IvMaxPos = ,
IvMinPos = ,
IvPos = ,
LaserStatus = true,
CouchMarkPos =
};
Service1Client client = new Service1Client();
string res = client.DoWork(move);
WCF扩展之实现ZeroMQ绑定和protocolBuffer消息编码(一)概要设计的更多相关文章
- WCF扩展之实现ZeroMQ绑定和protocolBuffer消息编码(二)实现IRequestChannel(2016-03-15 12:35)
这是这个系列的第二篇,其他的文章请点击下列目录 WCF扩展之实现ZeroMQ绑定和protocolBuffer消息编码(一)概要设计 WCF扩展之实现ZeroMQ绑定和protocolBuffer消息 ...
- WCF扩展之实现ZeroMQ绑定和protocolBuffer消息编码(三)实现ReplyChannel(2016-03-15 12:35)
这是这个系列的第三篇,其他的文章请点击下列目录 WCF扩展之实现ZeroMQ绑定和protocolBuffer消息编码(一)概要设计 WCF扩展之实现ZeroMQ绑定和protocolBuffer消息 ...
- WCF扩展系列 - 行为扩展(Behaviors)
原文地址:http://www.cnblogs.com/Creator/archive/2011/05/21/2052687.html 这个系列的第一部分将会重点关注WCF行为(behaviors), ...
- 【转】WCF扩展系列 - 行为扩展(Behaviors)
原文:https://www.cnblogs.com/Creator/archive/2011/05/21/2052687.html 这个系列的第一部分将会重点关注WCF行为(behaviors),W ...
- 真实世界:使用WCF扩展记录服务调用时间
WCF 可扩展性 WCF 提供了许多扩展点供开发人员自定义运行时行为. WCF 在 Channel Layer 之上还提供了一个高级运行时,主要是针对应用程序开发人员.在 WCF 文档中,它常被称为服 ...
- WCF 服务的ABC之绑定(六)
绑定 Binding 绑定是开发人员控制WCF程序与其他消息交互的主要手段.从功能上看,绑定创建了通道工厂惑通道侦听器的堆栈对象.绑定直接惑间接创建的对象是WCF实现各种消息功能(例如,传输.安全性. ...
- WCF扩展
WCF 可扩展性 WCF 提供了许多扩展点供开发人员自定义运行时行为. WCF 在 Channel Layer 之上还提供了一个高级运行时,主要是针对应用程序开发人员.在 WCF 文档中,它常被称为服 ...
- 扩展SpringMVC以支持绑定JSON格式的请求参数
此方案是把请求参数(JSON字符串)绑定到java对象,,@RequestBody是绑定内容体到java对象的. 问题描述: <span style="font-size: x-sma ...
- WCF 项目应用连载[8] - 绑定、服务、行为 大数据传输与限流 - 下 (ServiceThrottlingAttribute)
因为ORM的原因,对Attribute编程有一种情节..所以这节的出现,完全是因为在WCF对自定义Attribute的一种应用. WCF 项目应用连载[7] - 绑定.服务.行为 大数据传输与限流 - ...
随机推荐
- Java经典面试题及详解
Java基础方面: 1.作用域public,private,protected,以及不写时的区别 答:区别如下: 作用域 当前类 同一package ...
- 解决Delphi MDI 闪烁问题(使用WM_SETREDRAW锁屏后进行处理)
procedure TMainForm.CreateMDIChild(const Name: string); var Child: TMDIChild; begin { create a new M ...
- Oracle varchar2最大支持长度(转)
oerr ora 0650206502, 00000, "PL/SQL: numeric or value error%s"// *Cause: An arithmetic, nu ...
- POJ 3040 Allowance 贪心
这题目的贪心思路还是有一点细节问题的. 还没有证明,据说是因为题目给的条件是每个价格是比它小的价格的倍数才能这么贪心的. 思路如下: 假设要给奶牛的钱为C 1)从大面值到小面值一次拿钱,能拿多少拿多少 ...
- swfupload组件后台获取中文文件名称乱码的问题解决
问题描写叙述:用swfupload上传文件,含有中文名称的文件上传会报错,我用的是获取FileItem对象,用FileItem对象的getName()方法获取文件名会乱码,试着用request. ...
- 【Cocos2d-X开发笔记】第一期 Cocos2d-X的环境搭建
作者今天开始正式开始学习Cocos2d-X引擎进行游戏编程,预计两天会更新一期,最后实现ios游戏的appsore上线. (部分内容转载自:http://blog.csdn.net/yan ...
- How to use STA(sql tuning advisor)
一.手工生成Sql tuning advisor 1.SQL text format: DECLARE my_task_name VARCHAR2(30); my_sqltext CLO ...
- 应届GIS硕士求职经验总结
记录一下作为一个GIS应届毕业生在帝都找工作的历程吧,之后的经历可能丰富多彩,可能萎靡不振,但这一次走过来了就是这一次的.希望以史为鉴,各位客官也能有所收获. 定位 我们这一届的"烟酒生&q ...
- Android中<meta-data>的使用
在AndroidManifest.xml中.<meta-data>元素能够作为子元素,被包括在<activity>.<application> .<servi ...
- HDU 3699 A hard Aoshu Problem (暴力搜索)
题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(同样的字符串进行同样的数字替换), 替换后的三个数进行四则运算要满足左边等于右边.求有几种解法. Sample Input 2 ...