wcf通过https访问

ACCPY111 2009-10-19 04:21:34
大家可以参考http://www.cnblogs.com/frank_xl/archive/2009/08/13/1543848.html
爲什麽我在添加服务引用的時候在輸入https://localhost:9001/Service1后,提示的錯誤是:下载“https://localhost:9001/Service1”时出错。
无法连接到远程服务器
由于目标机器积极拒绝,无法连接。 127.0.0.1:9001
元数据包含无法解析的引用:“https://localhost:9001/Service1”。
无法连接到 https://localhost:9001/Service1。TCP 错误代码 10061: 由于目标机器积极拒绝,无法连接。 127.0.0.1:9001。
无法连接到远程服务器
由于目标机器积极拒绝,无法连接。 127.0.0.1:9001
如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。

证书这块我应该弄好了我可以用httpcfg query ssl查看:

IP : 127.0.0.1:9001
Hash : 719c6cac58dfb5 d3d 0d9a5355abf954e972e27
Guid : {00000000-0000-0000-0000-000000000000}
CertStoreName : (null)
CertCheckMode : 0
RevocationFreshnessTime : 0
UrlRetrievalTimeout : 0
SslCtlIdentifier : (null)
SslCtlStoreName : (null)
Flags : 0

这里有个问题Hash是不是就是证书的微缩图,在证书的详细信息里能够查看,还是就是怎么把HTTPS HOST 到 IIS?
我的app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- 部署服务库项目时,必须将配置文件的内容添加到
主机的 app.config 文件中。System.Configuration 不支持库的配置文件。-->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary.Service1" behaviorConfiguration="WcfServiceLibrary.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "https://localhost:9001" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- 除非完全限定,否则地址将与上面提供的基址相关 -->
<endpoint address ="Service1" binding="wsHttpBinding" contract="WcfServiceLibrary.IService1" bindingConfiguration="WcfServiceLibrary.Service1Binding" />

<!-- Metadata Endpoints -->
<!-- 元数据交换终结点由服务用于向客户端做自我描述。-->
<!-- 此终结点不使用安全绑定,应在部署前确保其安全或将其删除-->
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfServiceLibrary.Service1Behavior">
<!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点-->
<serviceMetadata httpGetEnabled="true"/>
<!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息-->
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceCredentials>
<serviceCertificate storeName="My" x509FindType="FindBySubjectName" findValue="WCFServerPK" storeLocation="LocalMachine"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WcfServiceLibrary.Service1Binding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
</configuration>


...全文
875 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuchengit 2011-12-09
  • 打赏
  • 举报
回复
楼主,,我也遇到同样的问题了。。不知道是否解决。。QQ:47307116
cdgrom123 2010-04-23
  • 打赏
  • 举报
回复
更正:
客户端配置文件的XML中错误:
WCFServerPK保存位置
应为
WCFClientPK保存位置

cdgrom123 2010-04-23
  • 打赏
  • 举报
回复
WCFServerPK:服务器证书
WCFClientPK:客户端证书
证书的Hash:缩略图、证书指纹
markcert命令已经在VS2008中集成,详情请参见MSDN
端口和证书的绑定要使用httpcfg命令,详情请参见MSDN
注:绑定命令中使用的Hash为WCFServerPK的Hash
绑定中所用hash值为服务器端要发送给客户端做认证的证书的缩略图(也叫做证书指纹)
WCFServerPK保存于服务器,并保证不被信任
WCFClientPK保存于服务器和客户端,并保证在服务器被信任

服务器端配置文件中:
<serviceCredentials>
<serviceCertificate storeName="WCFServerPK保存位置" findValue="WCFServerPK的Hash" storeLocation="LocalMachine" x509FindType="FindByThumbprint"/>
</serviceCredentials>


客户端配置文件中:
<clientCredentials>
<clientCertificate findValue="WCFClientPK的Hash" storeLocation="LocalMachine" storeName="WCFServerPK保存位置" x509FindType="FindByThumbprint"/>
</clientCredentials>


客户端不信任服务器解决办法:
使用.NET Frameworks基础类库强制客户端信任服务器证书

案例参见老徐的博客 http://www.cnblogs.com/frank_xl/category/203947.html
cdgrom123 2010-04-23
  • 打赏
  • 举报
回复
https使用ssl套接字,可以重新指定端口
楼上所述443端口是默认端口
我的WCF安全连接程序使用的是8085端口,交换证书认证才可以互访
zhongjiekangping 2009-10-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 findcaiyzh 的回复:]
证书的issuesto必须和你的访问web service的域名一样

https://localhost/Service1

另外https能用443以外的端口吗?
[/Quote]

没记错的话 应该不可以的
宝_爸 2009-10-20
  • 打赏
  • 举报
回复
证书的issuesto必须和你的访问web service的域名一样

https://localhost/Service1

另外https能用443以外的端口吗?
ACCPY111 2009-10-20
  • 打赏
  • 举报
回复
能不能说详细点什么叫证书的issuesto必须和你的访问web service的域名一样
ACCPY111 2009-10-20
  • 打赏
  • 举报
回复
怎么指定证书的颁发给
markcert该怎么使用
V68V6 2009-10-19
  • 打赏
  • 举报
回复
up

try
try

12,166

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧