WCF中常用的binding方式
WCF中常用的binding方式:
BasicHttpBinding: 用于把 WCF 服务当作 ASMX Web 服务。用于兼容旧的Web ASMX 服务。
WSHttpBinding: 比 BasicHttpBinding 更加安全,通常用于 non-duplex 服务通讯。
WSDualHttpBinding: 和 WSHttpBinding 相比,它支持 duplex 类型的服务。
WSFederationHttpBinding: WS-Federation 安全通讯协议。
NetTcpBinding: 使用 TCP 协议,用于在局域网(Intranet)内跨机器通信。有几个特点:可靠性、事务支持和安全,优化了 WCF 到 WCF 的通信。限制是服务端和客户端都必须使用 WCF 来实现。
NetNamedPipeBinding: 使用命名管道进行安全、可靠、高效的单机服务通讯方式。
NetMsmqBinding: 使用消息队列在不同机器间进行非连接通讯。
NetPeerTcpBinding: 使用 P2P 协议在多机器间通讯。
MsmqIntegrationBinding: 将 WCF 消息转化为 MSMQ 消息,使用现有的消息队列系统进行跨机器通讯。如 MSMQ。
|
名称 |
传输 |
编码 |
共同操作 |
|
BasicHttpBinding |
HTTP/HTTPS |
Text |
Yes |
|
NetTcpBinding |
TCP |
Binary |
No |
|
NetPeerTcpBinding |
P2P |
Binary |
No |
|
NetNamedPipeBinding |
IPC |
Binary |
No |
|
WSHttpBinding |
HTTP/HTTPS |
Text,MTOM |
Yes |
|
WSFederationBinding |
HTTP/HTTPS |
Text,MTOM |
Yes |
|
WSDualHttpBinding |
HTTP |
Text,MTOM |
Yes |
|
NetMsmqBinding |
MSMQ |
Binary |
No |
|
MsmqIntegrationBinding |
MSMQ |
Binary |
Yes |
|
Binding名称 |
Configuration Element |
描述 |
|
BasicHttpBinding |
basicHttpBinding |
一个指定用符合基本网络服务规范通讯的binding,它用http进行传输,数据格式为text/xml |
|
WSHttpBinding |
wsHttpBinding |
一个安全的通用的binding,但它不能在deplex中使用 |
|
WSDualHttpBinding |
wsDualHttpBinding |
一个安全的通用的binding,但能在deplex中使用 |
|
WSFederationHttpBinding |
wsFederationHttpBinding |
一个安全的通用的支持WSF的binding,能对用户进行验证和授权 |
|
NetTcpBinding |
netTcpBinding |
在wcf应用程序中最适合跨机器进行安全通讯的binding |
|
NetNamedPipeBinding |
netNamedPipeBinding |
在wcf应用程序中最适合本机进行安全通讯的binding |
|
NetMsmqBinding |
netMsmqBinding |
在wcf应用程序中最适合跨机器进行安全通讯的binding,并且支持排队 |
|
NetPeerTcpBinding |
netPeerTcpBinding |
一个支持安全的,多机交互的binding |
|
MsmqIntegrationBinding |
msmqIntegrationBinding |
一个用于wcf与现有msmq程序进行安全通讯的binding |
|
绑定类名称 |
传输 |
消息编码 |
消息版本 |
安全模式 |
可靠消息传送 |
事务流(默认情况下禁用) |
|
BasicHttpBinding |
HTTP |
文本 |
SOAP 1.1 |
无 |
不支持 |
不支持 |
|
WSHttpBinding |
HTTP |
文本 |
SOAP 1.2 WS-Addressing 1.0 |
消息 |
禁用 |
WS-AtomicTransactions |
|
WSDualHttpBinding |
HTTP |
文本 |
SOAP 1.2 WS-Addressing 1.0 |
消息 |
启用 |
WS-AtomicTransactions |
|
WSFederationHttpBinding |
HTTP |
文本 |
SOAP 1.2 WS-Addressing 1.0 |
消息 |
禁用 |
WS-AtomicTransactions |
|
NetTcpBinding |
TCP |
二进制 |
SOAP 1.2 |
传输 |
禁用 |
OleTransactions |
|
NetPeerTcpBinding |
P2P |
二进制 |
SOAP 1.2 |
传输 |
不支持 |
不支持 |
|
NetNamedPipesBinding |
命名管道 |
二进制 |
SOAP 1.2 |
传输 |
不支持 |
OleTransactions |
|
NetMsmqBinding |
MSMQ |
二进制 |
SOAP 1.2 |
消息 |
不支持 |
不支持 |
|
MsmqIntegrationBinding |
MSMQ |
不支持(使用 WCF 之前的序列化格式) |
不支持 |
传输 |
不支持 |
不支持 |
|
CustomBinding |
您决定 |
您决定 |
您决定 |
您决定 |
您决定 |
您决定 |
可以通过修改WCF配置文件来修改binding的方式,修改WCF配置文件可以使用VS自带的WCF配置修改工具(WCF Service Configuration Editor)
这里写一个配置文件的注释,这份是一个Service端的配置文件(不是Host,所以能公开元数据)。
<!-- Service端的配置文件,公开元数据与Http连接 -->
<system.serviceModel> WCF 配置开始
<behaviors> 一个服务器行为的配置开始
<serviceBehaviors>
<behaviorname="NewBehavior"> 配置一个行为 name:行为的名称
<serviceDebug /> 表示此service可以调试
<serviceMetadatahttpGetEnabled="true"httpsGetEnabled="false" />
元数据的配置, httpGetEnabled:是否可以使用Http来获取元数据,
httpsGetEnabled:是否可以使用Https来获取元数据
当设置为可以获取元数据, 就必须配置http或https的路径
</behavior>
</serviceBehaviors>
</behaviors> 服务器行为配置结束
<services> 服务器配置开始
<service behaviorConfiguration="NewBehavior" 配置一个服务器, behaviorConfiguration:指示服务行为,b连接到behaviors
name="Service"> name:服务类的位置
<endpoint 开始一个端口的配置
binding="basicHttpBinding" binding: 绑定类型 Http
contract=" IShopServiceV2" >
contract:公共接口的位置
</endpoint>
<endpoint 开始第二个端口的配置,这个端口是用于发布元数据
address="mex" address:端口的监听位置,mex表示设置成相对地址
binding="mexHttpBinding" binding: 绑定方式.
此处为元数据的绑定方式
mexHttpBinding(对于 HTTP 发布)。
mexHttpsBinding(对于 HTTPS 发布)。
mexNamedPipeBinding(对于命名管道发布)。
mexTcpBinding(对于 TCP 发布)。
contract="IMetadataExchange"/> contract:公共接口的位置
IMetadataExchange: 公开用于返回有关服务的元数据的方法。
<host> 主机配置
<baseAddresses>
<addbaseAddress="http:127.0.0.1:8001/WCFService" />
配置一个服务器的监听路径
</baseAddresses>
</host>
</service>
</services>
代理类生成:不单是WCF服务文件(.svn)能用工具(svcutil.exe)来生成客户端代理,即使使用WCF服务库也可以通过WCF服务主机的元数据地址来使用svcutil.exe生成代理。
一个双绑定,带配置文件的Host的Demo:
<system.serviceModel>
<services>
<servicename="Service">
<endpointbinding="netTcpBinding"contract="IShopServiceV2" />
<endpointbinding="basicHttpBinding"contract="IShopServiceV2" />
</service>
</services>
</system.serviceModel>
Uri tcpAddress = new Uri("net.tcp://localhost:9000/Service");
Uri httpAddress = new Uri("http://localhost:9001/Service");
ServiceHost Host = new ServiceHost(typeof(WCFCompnent.Service), tcpAddress, httpAddress);
Host.Open();
Console.WriteLine("服务已经启动!");
Console.Read();
Host.Close();
不带配置文件的Host:
Uri baseAddress = new Uri("net.tcp://localhost:9000/ServoceHost");
Uri mexAddress = new Uri("mex", UriKind.Relative);
using (ServiceHost serviceHost = new ServiceHost(typeof(Service), baseAddress))
{
NetTcpBinding binding = new NetTcpBinding();
serviceHost.AddServiceEndpoint(typeof(PublicElements.publicInterface.IService), binding, baseAddress);
serviceHost.Open();
Console.WriteLine("服务器已经打开");
Console.WriteLine("按任意键关闭");
Console.Read();
serviceHost.Close();
}
WCF中常用的binding方式的更多相关文章
- WCF中常用的binding方式 z
WCF中常用的binding方式: BasicHttpBinding: 用于把 WCF 服务当作 ASMX Web 服务.用于兼容旧的Web ASMX 服务. WSHttpBinding: 比 Bas ...
- NAND Flash中常用的纠错方式(ECC算法)
Hanming,RS,BCH —— NAND Flash中常用的纠错方式 因为闪存中会有出错的可能,如果没有使用ECC模块,读出的数据和写入的数据会有不匹配的可能,也许一个文件中只有一两个bit不匹配 ...
- 基础篇:1.JavaScript运行在html中,引用有几种方式?—— 6.js中常用的输出方式?
书接上文,上文提到若干条JavaScript的基础性知识,大部分都是一些概念性的东西,本着认真严谨的态度,我们要认真对待,有些条目的问题是某个知识点的周边延伸,为节约篇幅,就一起整理了,如有描述不对的 ...
- java中常用的加密方式
加密,是以某种特殊的算法改变原有的信息数据,使得未授权的用户即使获得了已加密的信息,但因不知解密的方法,仍然无法了解信息的内容.大体上分为双向加密和单向加密,而双向加密又分为对称加密和非对称加密(有些 ...
- Java中常用的加密方式(附多个工具类)
一.Java常用加密方式 Base64加密算法(编码方式) MD5加密(消息摘要算法,验证信息完整性) 对称加密算法 非对称加密算法 数字签名算法 数字证书 二.分类按加密算法是否需要key被分为两类 ...
- cocos2dx 游戏开发中常用场景切换方式以及特性
runWithScene(CCScene* scene):启动游戏,并运行scene 场景.这个方法在主程序启动时第一次启动主场景时调用. replaceScene(CCScene* scene) ...
- JS中常用的输出方式(五种)
1.alert("要输出的内容"); ->在浏览器中弹出一个对话框,然后把要输出的内容展示出来 ->alert都是把要输出的内容首先转换为字符串然后在输出的 2.doc ...
- Input类中常用的验证方式
Deolin一般将Input类对象作为POST请求方法的参数, Input类的域与前端的数据结构一一对应,由于后端不应该相信前端传过来的任何数据, 所以前端的数据对象先绑定到Input对象中,通过JS ...
- 在2d游戏中常用的向量方式
function cc.exports.VectorRotateByAngle(vector,angle)--计算向量旋转后的向量,angle:正数逆时针,负输顺时针 angle = angle*ma ...
随机推荐
- FastDFS----recovery状态问题排查记录
FastDFS问题排查记录现象今天有人反馈,客户端部分图标时而不能显示问题定位用jemter将图片地址进行简单测试后,发现偶尔有404 NOT FOUND的情况在服务器上对八台nginx分别进行测试 ...
- 搭建sonar,推动代码质量管理
最近比较关注devops相关的文章,尝试搭建sonarqube服务,进行代码质量的分析和管理,先记录下本地环境的搭建和分析过程. 一.sonarqube服务搭建 官网地址:http://www.son ...
- Android 增量更新(BSDiff / bspatch)
Android 增量更新 BSDiff / bspatchhttp://www.daemonology.net/bsdiff/android的代码目录下 \external\bsdiff bsdiff ...
- js对话框5秒自动消失
使用了easyui的对话框控件 <html> <head> <title>5秒后关闭对话框</title> <meta http-equiv=&q ...
- 错误 1 error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. d:\users\vs2013\le
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>void main(){ int nu ...
- 解决类似 Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)的问题
源码编译升级安装了gcc后,编译程序或运行其它程序时,有时会出现类似/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found的问题.这 ...
- Linux使用ssh公钥实现免密码登录Linux
ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例.有机器A(192.168.1.155),B(192.168.1.181).现想A ...
- jave占用CPU较高
转自http://www.tuicool.com/articles/YFVbia Linux下java进程CPU占用率高-分析方法 时间 2014-01-04 12:18:44 IT社区推荐资讯 原文 ...
- pyqt5安装
花了一天时间,终于是装好了. 这东西硬是把我从Python2掰弯成了Python3 本来用pip安装了一个pyqt,但是后来才发现,这是个x64版本的. 我不知道啊! 我以为是还要装qt5 所以我把q ...
- Linux下搭建SVN服务器及自动更新项目文件到web目录(www)的方法
首先搭建SVN服务器 1,安装SVN服务端 直接用apt-get或yum安装subversion即可(当然也可以自己去官方下载安装) sudo apt-get install subversion ...