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] - 绑定.服务.行为 大数据传输与限流 - ...
随机推荐
- 虚继承之单继承的内存布局(VC在编译时会把vfptr放到类的头部,这和Delphi完全一致)
C++2.0以后全面支持虚函数与虚继承,这两个特性的引入为C++增强了不少功能,也引入了不少烦恼.虚函数与虚继承有哪些特性,今天就不记录了,如果能搞了解一下编译器是如何实现虚函数和虚继承,它们在类的内 ...
- Delphi的指针 good
Pointers are like jumps, leading wildly from one part of the data structure to another. Their introd ...
- js下读取input中的value值
很多人(包括我),总想像以前操作js一样,读取到input中的值:document.getElementById('').value; 结果事实证明这样读到得是null. eval(document. ...
- Referer反反盗链
0x00 前言 最近用Python非常多,确实感受到了Python的强大与便利.但同时我并没有相见恨晚的感觉,相反我很庆幸自己没有太早接触到Python,而是基本按着C→C++→Java→Python ...
- MySQL分区技术 (一)
4:MySQL 分区技术(是mysql 5.1以版本号后開始用->是甲骨文mysql技术团队维护人员以插件形式插入到mysql里面的技术) 眼下,针对海量数据的优化主要有2中方法: 1:大表拆成 ...
- c++windows内核编程笔记day12 硬盘逻辑分区管理、文件管理、内存管理
windows系统磁盘文件存储: 分区格式:NTFS / FAT32 GetSystemDirectory();//获取系统路径 GetWindowsDirectory();//获取windows路径 ...
- EF中的事务处理的初步理解
http://yanwushu.byethost7.com/?p=87 1. EF对事务进行了封装:context的saveChange()是有事务性的. 2. 依赖多个不同的Context的操作(即 ...
- HDU4719-Oh My Holy FFF(DP线段树优化)
Oh My Holy FFF Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) T ...
- hdu4105 Electric wave
Electric wave Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- java -D參数简化增加多个jar【简化设置classpath】
1.-D<name>=<value> set a system property 设置系统属性. java命令引入jar时能够-cp參数,但时-cp不能用通配符(多个jar时 ...