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客户端如何为双工服务 ...
随机推荐
- 一步一步做出属于自己的Eclipse
本文将教大家一步一步打造属于自己的eclipse,涉及到地方,不完全之处请谅解. 一.下载 进入eclipse网站:http://www.eclipse.org/downloads/ 下载:Eclip ...
- 将Linux默认的OpenJDK替换为Oracle JDK
在使用Logstash安装插件的时候,发生了一个错误,如下: ERROR: Something went wrong when installing logstash-input-jdbc, mess ...
- information_schema系列十
information_schema系列十 1:INNODB_FT_CONFIG 这张表存的是全文索引的信息,查询前可以先通过以下语句查询一下开启全文索引的表: show variables li ...
- 阿里云centos中mysql的安装及一些常识知识
------------------------------------------------------------------- 阿里云centos中mysql的安装 工具WinSCP v ...
- ptime概述
官方给出的ptime的定义是:ptime gives the length of time in milliseconds represented by themedia in a packet.简单 ...
- QT中文乱码与国际化支持
QT国际化支持 Qt内部采用的全Unicode编码,这从根本上保证了多国语界面实现的正确性和便捷性.Qt本身提供的linguist工具,用来实现翻译过程十分方便.MFC中利用资源DLL切换资源,或 ...
- [转]QT QDateTime类、QTimer类
QDateTime类,头文件#include <QDateTime> 可以使用QDateTime类来获得系统时间.通过QDateTime::currentDateTime()来获取本地系统 ...
- Tensorflow 模型持久化saver及加载图结构
主要内容: 1. 直接保存,加载模型; (可以指定加载,保存的var_list) 2. 加载,保存指定变量的模型 3. slim加载模型使用 4. 加载模型图结构和参数等 tensorflow 恢复部 ...
- Excel表数据导入Sql Server数据库中
Excel表数据导入Sql Server数据库的方法很多,这里只是介绍了其中一种: 1.首先,我们要先在test数据库中新建一个my_test表,该表具有三个字段tid int类型, tname nv ...
- Unique Binary Search Trees II leetcode java
题目: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. F ...