通过https调用WebService

时间:2016-02-08 18:57:43

标签: web-services https web-config

我创建了一个webService来生成pdf文件。在VisualStudio 2012的调试模式下。没关系。我可以从其他IntranetSite调用它。

我尝试将它放在我的测试服务器上。但我需要添加https而不是http。

我找到this 我尝试像我这样改编自web.config

<system.serviceModel>
<bindings>
  <basicHttpBinding>
      <binding name="GenerationCourriersSoap" >
          <security mode="Transport">
              <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
              <message clientCredentialType="Certificate" algorithmSuite="Default" />
          </security>
      </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
<behavior name="secureBehaviours">
  <serviceMetadata httpsGetEnabled="true"/>
</behavior>
 </serviceBehaviors>
</behaviors>
 <client>
<endpoint address="https://localhost:52999/GenerationCourrier.asmx"
binding="basicHttpBinding" bindingConfiguration="GenerationCourriersSoap"
contract="WSCourrier.GenerationCourriersSoap" name="GenerationCourriersSoap"    />
</client>
</system.serviceModel>

但我有消息

  

无法与权限为“localhost:52999”的安全通道SSL / TLS建立信任。

我直接使用IIS的auto-certicate buid。 我验证,此证书位于我的root和安全文件夹中 有人有想法吗?

1 个答案:

答案 0 :(得分:0)

最后我找到了这个enter link description here

看起来不错。现在我可以访问webService了。

理念是强制验证所有证书。就像那个测试期一样

Imports System
Imports System.Net
Imports System.Security.Cryptography.X509Certificates

Public Class clsSSL
    Public Function AcceptAllCertifications(ByVal sender As Object, ByVal certification As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
        Return True
    End Function
End Class

在调用WebService函数之前调用函数

ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications
相关问题