asp.net 调用带证书的webservice解决办法

最近在朋友弄一个调整省政府政务工作流的程序。。

 

需要把当前的信息推送到政务网上,采用的是带证书的https webservice。。

 

下面说一下实现过程

 

第一步,引用webservice地址,删除web.config中相关配置。同时安装好证书

 

用如下数据替换:

 

[html] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. <system.serviceModel>  
  2.   <bindings>  
  3.     <customBinding>  
  4.       <binding name="IServiceSoapBinding" closeTimeout="00:01:00"  
  5.               openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">  
  6.         <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"  
  7.       messageVersion="Soap11" writeEncoding="utf-8">  
  8.           <!-- 政务大厅接口需要使用Soap11 -->  
  9.           <readerQuotas maxDepth="32" maxStringContentLength="819200000" maxArrayLength="1638400000"  
  10.             maxBytesPerRead="4096000" maxNameTableCharCount="16384000" />  
  11.         </textMessageEncoding>  
  12.         <httpsTransport manualAddressing="false" maxBufferPoolSize="52428800"  
  13.           maxReceivedMessageSize="6553600" allowCookies="false" authenticationScheme="Anonymous"  
  14.           bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"  
  15.           keepAliveEnabled="true" maxBufferSize="6553600" proxyAuthenticationScheme="Anonymous"  
  16.           realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"  
  17.           useDefaultWebProxy="true" requireClientCertificate="true" />  
  18.       </binding>  
  19.     </customBinding>  
  20.   </bindings>  
  21.   <client>  
  22.     <endpoint address="https://WebService网址/CXFWebService/webservice/iservice" behaviorConfiguration="endpointBehavior1" binding="customBinding" bindingConfiguration="IServiceSoapBinding" contract="ZwdtServices.IService" name="ServiceImplPort" />  
  23.   </client>  
  24.   <behaviors>  
  25.     <endpointBehaviors>  
  26.       <behavior name="endpointBehavior1">  
  27.         <dataContractSerializer maxItemsInObjectGraph="209715200"/>  
  28.         <clientCredentials>  
  29.           <clientCertificate  findValue="证书用户" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>  
  30.           <serviceCertificate>  
  31.             <authentication certificateValidationMode="None"/>  
  32.             <!--<defaultCertificate findValue="ShanXi Digital Certificate Authority" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My"/>-->  
  33.           </serviceCertificate>  
  34.         </clientCredentials>  
  35.       </behavior>  
  36.     </endpointBehaviors>  
  37.   </behaviors>  
  38. </system.serviceModel>  


但在实际调用时,提示找不到对应的证书用户

 

 

我猜测可能是iis用户访问证书有关,那么就在用户和计算机上都导入证书。运行MMC,打开两个证书管理器,都把证书导入一次。

如图

 

 

完成之后,果然错误不一样。。

继续运行,出现没有权限的错误

 

继续设计证书权限

 

 

 

OK完成。。。。。

posted @ 2016-07-21 13:51  四神  阅读(798)  评论(0编辑  收藏  举报