WCF分布式开发常见错误(23):This could be due to the fact that the server certificate is not configured properly with HTTP.SYS
来源:互联网 发布:北京银行学知支行 编辑:程序博客网 时间:2024/05/16 17:12
当使用Transport安全模式,WSHTTPBingding, 客户端认证类型为Windows:clientCredentialType="Windows" .
安装了证书,也添加了客户端服务引用。启动服务宿主,客户端也添加了账号。结果就出错了。
信息如下:
An error occurred while making the HTTP request to https://localhost:9001/WCFService. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.
可能是由于服务器证书在HTTPS 箱子里与HTTP.SYS 设置不匹配。也可以由于客户端和服务端之间的绑定不一致导致。
问题发到WCF中英文论坛,一个WCF英文论坛版主Richard,给了提示。他自己的一个连接。我看了一下。有点收获。
WCF中文论坛问题地址:http://social.microsoft.com/Forums/zh-CN/wcfzhchs/thread/5ca6ee28-76cb-4395-82ea-21160cd4ebb0
WCF英文论坛问题地址:http://social.microsoft.com/Forums/en-US/wcf/thread/c39ce206-a86b-4faf-a427-8d4e4684758c
【1】错误信息截图:
【2】问题原因:
导致此问题的原因可能是:
(1)证书没有设置,transport安全模式,需要建立SSL安全套接层或者TLS传输层安全协议。服务器要提供证书。
(2)WCF终结点地址没有设置证书,这里要建立SSL需要对中节点地址设置证书。
【3】解决办法:
(1)制作证书:这里直接使用makecert 工具。Microsoft Visual Studio 2008-->Visual Studio Tools-->Visual Studio 2008 命令提示行里输入:
makecert -r -pe -n "CN=FrankWCFServer" -ss My -sky exchange
具体大家可以看文章WSE3.0构建Web服务安全(2):非对称加密、公钥、密钥、证书、签名的区别和联系以及X.509 证书的获得和管理,详细的介绍。具体的参数说明:详细帮助文档:
(2)设置服务证书:
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<serviceCertificate x509FindType="FindBySubjectName" findValue="WCFHTTPS" storeLocation="CurrentUser"/>
</serviceCredentials>
</behavior>
(3)为服务终结点地址注册SSL证书:
现在证书还不可用,需要为使用的端口注册证书。这里需要设置工具,Windows Server 2003 或 Windows XP,则使用 HttpCfg.exe 工具。Windows Server 2003 中已安装该工具。下载该工具/Files/frank_xl/HttpcfgFrankXuLei.rar。
如果运行的是 Windows Vista,则使用已安装的 Netsh.exe 工具。在Windows/System32目录下。
【4】SSL证书设置过程:
要查出证书指纹的值,在浏览器--内容--证书里,选择你创建的证书-详细信息--微缩图(thumbprint其实是指纹的意思)把这个值拷贝出来,中间的空格可以再文本编辑器里替换掉。这里WCFHTTPS的是0307d727a369378d077809cf0ed617eec90a0e2f。
【4.1】查询SSL证书设置:
(1)在 Windows Server 2003 或 Windows XP 中,通过 query 和 ssl 开关使用 HttpCfg.exe 工具查看当前端口配置,在命令窗口切换到HttpCfg在文件目录,你如下面代码:
httpcfg query ssl
(2)Vista:
netsh http show sslcert
【4.2】设置SSL证书:
(1)在 Windows Server 2003 或 Windows XP:
httpcfg set ssl -i 0.0.0.0:9001-h 0307d727a369378d077809cf0ed617eec90a0e2f
(2)Vista:
netsh http add sslcert ipport=0.0.0.0:9001 certhash=0307d727a369378d077809cf0ed617eec90a0e2f appid={111111111-2222-3333-4444-qqqqqqqqqqqqq} 。最后一个GUID.你可以随便编写一个。使用工具也可以。certhash 参数指定证书的指纹。ipport 参数指定 IP 地址和端口,功能类似于前述 Httpcfg.exe 工具的 -i 开关。appid 参数为可用于标识所属应用程序的 GUID。
【4.3】删除SSL证书:
(1)Windows Server 2003 和 Windows XP 中:
httpcfg delete ssl -i 0.0.0.0:9001-h 0307d727a369378d077809cf0ed617eec90a0e2f
(2)Vista:
Netsh http delete sslcert ipport=0.0.0.0:9001
【5】总结:
配置完成以后,就可以启动托管宿主了。SSL证书配置相对复杂。在实现传输安全的是时候需要设置证书到特定的端口。很多代码都没给出提示。这个需要注意。大部分文章之给出理论,实际对问题解决参考不大,代码实际开发需要自己实践。我在解决这个问题的时候,尝试了很多方式。结果结果就是不对,快包崩溃的时候,试验成功了。这个就是最开心的。
运行宿主结果如下:
参考资料:
1.WSE3.0构建Web服务安全(2):非对称加密、公钥、密钥、证书、签名的区别和联系以及X.509 证书的获得和管理
2.http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cptools/html/cpgrfcertificatecreationtoolmakecertexe.asp
3.http://msdn.microsoft.com/en-us/library/ms733791.aspx
4.WCF分布式开发常见错误(22):The caller was not authenticated...如何在XP系统为WCF设置可信任的证书
【老徐的博客】
【作 者】:Frank Xu Lei
【地 址】:http://www.cnblogs.com/frank_xl/
【中文论坛】:微软WCF中文技术论坛
【英文论坛】:微软WCF英文技术论坛
- WCF分布式开发常见错误(23):This could be due to the fact that the server certificate is not configured properly with HTTP.SYS
- the selected server is enabled,but is not configured properly.Deployment to it will not be permitted
- WCF分布式开发常见错误(4):The type or namespace name 'DataContract' could not be found DataContract找不到
- Unable to logon to the server. Your login credentials not be configured properly (-12)".
- WCF分布式开发常见错误(24):Could not establish trust relationship for the SSL/TLS secure channel with authority
- WCF分布式开发常见错误(25):The certificate 'CN=WCFHTTPS' must have a private key that is capable of key exchange
- When connecting to SQL Server 2005, this failure may be caused by the fact that under the defa
- Unable to start debugging on the web server. The project is not configured to be debugged.
- Unable to start debugging on the web server. The project is not configured to be debugged.
- 404报错:The server cannot or will not process the request due to something that is perceived to be a c
- WCF分布式开发常见错误(28):The requested upgrade is not supported by...
- IIS 7 The Web server is configured to not list the contents of this directory
- Mysql 出现错误The server is not configured as slave; fix in config file or with CHANGE MASTER TO
- WCF分布式开发常见错误(5)Could not find a base address that matches scheme
- To be or Not to be that is the question
- WCF分布式开发常见错误(27):Secure channel cannot be opened because security negotiation with the remote endpoint has failed
- WCF分布式开发常见错误(12):The server was unable to process the request,服务无法处理请求
- WCF分布式开发常见错误解决(12):The server was unable to process the request,服务无法处理请求
- WCF分布式安全开发实践(2):传输安全模式之基本身份验证(Windows账户密码):Transport_Basic_WSHttpBinding
- WCF分布式安全开发实践(1):传输安全模式之匿名客户端:Transport_None_WSHttpBinding
- WCF分布式安全开发实践(10):消息安全模式之自定义用户名密码:Message_UserNamePassword_WSHttpBinding
- WCF分布式安全开发实践(0):文章和代码结构规划介绍
- WCF分布式开发常见错误(24):Could not establish trust relationship for the SSL/TLS secure channel with authority
- WCF分布式开发常见错误(23):This could be due to the fact that the server certificate is not configured properly with HTTP.SYS
- WCF分布式开发步步为赢(14):WCF安全编程--基本概念
- WCF分布式开发常见错误(22):The caller was not authenticated...如何在XP系统为WCF设置可信任的证书
- WCF分布式开发常见错误(21):unable to open its IChannelListener.分发器未能打开侦听器
- WCF分布式开发常见错误(20):TimeoutException was unhandled
- WCF热门问题编程示例(3):WCF是否使用或者支持IOCP完成端口(整理补充)
- 经典技术文章翻译(2)Does WCF use or Supports IOCP?WCF是否支持或者使用了IOCP完成端口。
- WCF分布式开发步步为赢(13):WCF服务离线操作与消息队列MSMQ
- WCF热门问题编程示例(2)多个实例调用一个WCF服务操作,需要等待服务响应吗