WCF 客户端 BasicHttpBinding 兼容 HTTPS 和 HTTP
背景:全站HTTPS的时代来了
全站HTTPS,请参考:http://www.cnblogs.com/bugly/p/5075909.html
1. 设置BasicHttpBinding的BasicHttpSecurity模型。
create Binding时通过URI的Scheme来判断是HTTPS还是HTTP.
internal class AtomBinding
{
private AtomBinding()
{
} internal static BasicHttpBinding Create(bool isHttps)
{
return new BasicHttpBinding
{
MaxReceivedMessageSize = 65536000,
ReaderQuotas = new XmlDictionaryReaderQuotas {MaxStringContentLength = 65536000}, // 设置BasicHttpBinding的安全(BasicHttpSecurity类型)
Security =
{
// 安全模型:如果是访问的HTTPS svc,则安全模型设置为Transport,HTTP设置为None(默认)
Mode = isHttps ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None, // 信息传输等级安全设置,客户端凭证采用默认的匿名认证
Transport = new HttpTransportSecurity {ClientCredentialType = HttpClientCredentialType.None}
}
};
}
}
2. BasicHttpSecurity类型介绍
- 2.1. Message
Security is provided using SOAP message security. For the BasicHttpBinding, the system requires that the server certificate be provided to the client separately. The valid client credential types for this binding are UserName and Certificate.(客户端需要提供用户名+密码以及证书,Basic Authentication==户名+密码)
- 2.2. None
The SOAP message is not secured during transfer. This is the default behavior.(默认的方式,没有任何安全措施,不能保证信息的完整性和保密性)
- 2.3. Transport
Security is provided using HTTPS. The service must be configured with SSL certificates. The SOAP message is protected as a whole using HTTPS. The service is authenticated by the client using the service’s SSL certificate. The client authentication is controlled through the ClientCredentialType.(通过HTTPS来保证信息安全,客户端的认证取决于ClientCredentialType的配置)
- 2.4. TransportCredentialOnly
This mode does not provide message integrity and confidentiality(这种方式不保证信息的完整性和机密性). It provides only HTTP-based client authentication. Use this mode with caution. It should be used in environments where the transfer security is being provided by other means (such as IPSec) and only client authentication is provided by the Windows Communication Foundation (WCF) infrastructure.
- 2.5. TransportWithMessageCredential
Integrity, confidentiality and server authentication are provided by HTTPS. The service must be configured with a certificate. Client authentication is provided by means of SOAP message security. This mode is applicable when the user is authenticating with a UserName or Certificate credential and there is an existing HTTPS deployment for securing message transfer.(这种方法最安全,但也最繁琐)
3. 客户端忽略对服务器端证书的校验
public AtomResponse Execute(AtomRequest message)
{
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policyErrors) => true;
return Channel.Execute(message);
}
如果客户端不忽略对服务器端证书的校验,则必须在客户端安装服务器端证书的根证书。
WCF 客户端 BasicHttpBinding 兼容 HTTPS 和 HTTP的更多相关文章
- Java与WCF交互(二):WCF客户端调用Java web service【转】
原文:http://www.cnblogs.com/downmoon/archive/2010/08/25/1807982.html 在上篇< Java与WCF交互(一):Java客户端调用WC ...
- 转载——Java与WCF交互(二):WCF客户端调用Java Web Service
在上篇< Java与WCF交互(一):Java客户端调用WCF服务>中,我介绍了自己如何使用axis2生成java客户端的悲惨经历.有同学问起使用什么协议,经初步验证,发现只有wsHttp ...
- 在代码生成工具Database2Sharp中使用ODP.NET(Oracle.ManagedDataAccess.dll)访问Oracle数据库,实现免安装Oracle客户端,兼容32位64位Oracle驱动
由于我们开发的辅助工具Database2Sharp需要支持多种数据库,虽然我们一般使用SQLServer来开发应用较多,但是Oracle等其他数据库也是常用的数据库之一,因此也是支持使用Oracle等 ...
- WCF客户端和服务的实现
WCF客户端和服务 ?服务器端: – 定义和实现服务契约 – 为服务类型构建ServiceHost实例,暴露endpoints – 打开通讯通道 ?客户端: – 需要服务契约的一个副本和关于endpo ...
- 终于解决:升级至.NET 4.6.1后VS2015生成WCF客户端代理类的问题
在Visual Studio 2015中将一个包含WCF引用的项目的targetFramework从4.5改为4.6.1的时候,VS2015会重新生成WCF客户端代理类.如果WCF引用配置中选中了&q ...
- WCF初探-10:WCF客户端调用服务
创建WCF 服务客户端应用程序需要执行下列步骤: 获取服务终结点的服务协定.绑定以及地址信息 使用该信息创建 WCF 客户端 调用操作 关闭该 WCF 客户端对象 WCF客户端调用服务存在以下特点: ...
- WCF初探-11:WCF客户端异步调用服务
前言: 在上一篇WCF初探-10:WCF客户端调用服务 中,我详细介绍了WCF客户端调用服务的方法,但是,这些操作都是同步进行的.有时我们需要长时间处理应用程序并得到返回结果,但又不想影响程序后面代码 ...
- WCF初探-12:WCF客户端异常处理
前言: 当我们打开WCF基础客户端通道(无论是通过显式打开还是通过调用操作自动打开).使用客户端或通道对象调用操作,或关闭基础客户端通道时,都会在客户端应用程序中出现异常.而我们知道WCF是基于网络的 ...
- WCF初探-13:WCF客户端为双工服务创建回调对象
前言: 在WCF初探-5:WCF消息交换模式之双工通讯(Duplex)博文中,我讲解了双工通信服务的一个应用场景,即订阅和发布模式,这一篇,我将通过一个消息发送的例子讲解一下WCF客户端如何为双工服务 ...
随机推荐
- MAPI错误0x80040107
MAPI错误0x80040107 的解决方案: The MAPI error means there's an "invalid entry" within the contac ...
- [转]mysql变量使用总结
From : http://www.cnblogs.com/wangtao_20/archive/2011/02/21/1959734.html set语句的学习: 使用select定义用户变量的实践 ...
- 深度学习Github排名,很不错的介绍
今天看到这篇文章,把深度学习github排名靠前的项目,介绍了一下,很不错: https://blog.csdn.net/yH0VLDe8VG8ep9VGe/article/details/81611 ...
- C#中转义字符[转]
https://www.cnblogs.com/muran/p/3174865.html 编程中很多细节问题我们都要十分的注意,要不一个小小的字母错误就能引起程序的无法运行. C#中转义字符分2中,一 ...
- ubuntu服务器常见使用技巧及-kill掉后GPU显存不释放进程-
如何解决python进程被kill掉后GPU显存不释放的问题 1 重新开一个shell,然后输入: ps aux|grep user_name|grep python.所有该用户下的python程序就 ...
- 如何得知当前机器上安装的PowerShell是什么版本的?
$PSVersionTable.PSVersion 参考资料 ================ http://stackoverflow.com/questions/1825585/determi ...
- Redis 在线管理工具(phpRedisAdmin)介绍
phpRedisAdmin is a simple web interface to manage Redis databases. phpRedisAdmin 在 Redis clients 的列表 ...
- Delphi获取默认打印机名称及端口
Delphi获取默认打印机名称及端口 在前段时间写的收银系统中由于目前市场上很多电脑主板上已经没有并口,而POS机却又需要并口,所以目前需要用PCI转接卡,这个就导致不同门店使用的端口就有可能不同,这 ...
- Linux Kernel 2:用户空间的初始化
上篇我们知道,kernel初始化后将启动init进程,那么这个进程将干些什么呢?除此之外,kernel还需要做些什么事情呢?(想想文件系统.根存储设备是在什么时候初始化的呢?) 先从文件系统初始化说起 ...
- create-react-app时registry的奇怪问题
用React官方给的NPM脚本 create-react-app my-app 在自动安装module的过程中,在安装registry的组件的时候莫名其妙的挂住不动了.界面显示的信息如下: fetch ...