背景:全站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的更多相关文章

  1. Java与WCF交互(二):WCF客户端调用Java web service【转】

    原文:http://www.cnblogs.com/downmoon/archive/2010/08/25/1807982.html 在上篇< Java与WCF交互(一):Java客户端调用WC ...

  2. 转载——Java与WCF交互(二):WCF客户端调用Java Web Service

    在上篇< Java与WCF交互(一):Java客户端调用WCF服务>中,我介绍了自己如何使用axis2生成java客户端的悲惨经历.有同学问起使用什么协议,经初步验证,发现只有wsHttp ...

  3. 在代码生成工具Database2Sharp中使用ODP.NET(Oracle.ManagedDataAccess.dll)访问Oracle数据库,实现免安装Oracle客户端,兼容32位64位Oracle驱动

    由于我们开发的辅助工具Database2Sharp需要支持多种数据库,虽然我们一般使用SQLServer来开发应用较多,但是Oracle等其他数据库也是常用的数据库之一,因此也是支持使用Oracle等 ...

  4. WCF客户端和服务的实现

    WCF客户端和服务 ?服务器端: – 定义和实现服务契约 – 为服务类型构建ServiceHost实例,暴露endpoints – 打开通讯通道 ?客户端: – 需要服务契约的一个副本和关于endpo ...

  5. 终于解决:升级至.NET 4.6.1后VS2015生成WCF客户端代理类的问题

    在Visual Studio 2015中将一个包含WCF引用的项目的targetFramework从4.5改为4.6.1的时候,VS2015会重新生成WCF客户端代理类.如果WCF引用配置中选中了&q ...

  6. WCF初探-10:WCF客户端调用服务

    创建WCF 服务客户端应用程序需要执行下列步骤: 获取服务终结点的服务协定.绑定以及地址信息 使用该信息创建 WCF 客户端 调用操作 关闭该 WCF 客户端对象 WCF客户端调用服务存在以下特点: ...

  7. WCF初探-11:WCF客户端异步调用服务

    前言: 在上一篇WCF初探-10:WCF客户端调用服务 中,我详细介绍了WCF客户端调用服务的方法,但是,这些操作都是同步进行的.有时我们需要长时间处理应用程序并得到返回结果,但又不想影响程序后面代码 ...

  8. WCF初探-12:WCF客户端异常处理

    前言: 当我们打开WCF基础客户端通道(无论是通过显式打开还是通过调用操作自动打开).使用客户端或通道对象调用操作,或关闭基础客户端通道时,都会在客户端应用程序中出现异常.而我们知道WCF是基于网络的 ...

  9. WCF初探-13:WCF客户端为双工服务创建回调对象

    前言: 在WCF初探-5:WCF消息交换模式之双工通讯(Duplex)博文中,我讲解了双工通信服务的一个应用场景,即订阅和发布模式,这一篇,我将通过一个消息发送的例子讲解一下WCF客户端如何为双工服务 ...

随机推荐

  1. 使用jupyter搭建golang的交互式界面:类似于ipython;jupyter还可以使用spark或者结合机器学习

    Jupyter Notebook The Jupyter notebook is a web-based notebook environment for interactive computing. ...

  2. Linux命令之du

    Linux du命令用来查看文件或目录所占用磁盘空间的大小(Summarize disk usage of each FILE, recursively for directories.) 语法: d ...

  3. 奇怪吸引子---Arneodo

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  4. 阿里NLP总监分享-NLP技术的应用与思考

    https://yq.aliyun.com/articles/78031 NLP技术的应用及思考

  5. CSS-设置Footer始终在页面底部

    Footer顾名思义页脚,如果内容多的时候在底部时感官很好,但是当内容变少(无法撑开一屏的时候)footer不固定在底部,影响美观,对于已经从事前端工作的工作的来说应该是比价工作中入门级别的问题了,由 ...

  6. ionic_ Network connectivity error occurred, are you offline?

    错误如下: HenHouse admin$ ionic cordova build ios --prod > ionic integrations enable cordova ✖ Downlo ...

  7. Structured Streaming编程向导

    简介 Structured Streaming is a scalable and fault-tolerant stream processing engine built on the Spark ...

  8. Redis:按照正则批量删除key

    Redis按照正则批量删除key redis目前还不支持批量删除key的命令,但是我们有时需要删除符合某个规则的keys,有两种方式: 1.使用redis-cli keys "test*&q ...

  9. IncrediBuild 2.40 过期时间

    IncrediBuild 2.40的License有2个文件CoordLicense.dat和AgentLicense.dat,分别位于Coordinator和Agent安装目录下,这两个文件都是RS ...

  10. 【Python】torrentParser1.03

    #------------------------------------------------------------------------------------ # torrentParse ...