.Net(C#)访问X509证书加密的Webservice(四)--客户端访问WCF

 C#代码调用webservice

设置客户端的证书

设置服务器证书

NameSpace.PaExportWebserviceProviderClient client2 = new NameSpace.PaExportWebserviceProviderClient();
client2.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "certClientName");
client2.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "certServerName");
client2.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
string webSvcResponse2 = client.connectionTest("test");//调用方法

App.Config配置,更改设置,根据使用的认证模式,更改,注意高亮的地方

  <binding name="PaExportWebserviceProviderServiceSoapBinding1"
          closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
          sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
          hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Message">
            <transport />
            <message clientCredentialType="Certificate" algorithmSuite="Default" />
          </security>
        </binding>
  <client>
      <endpoint address="http://xxxxxxxxxxxxxxx"
        binding="basicHttpBinding" bindingConfiguration="PaExportWebserviceProviderServiceSoapBinding"
        contract="NameSpace.IPaExportWebserviceProvider" name="PaExportWebserviceProviderPort" >
        <identity>
          <dns value="certServerName" />
        </identity>
      </endpoint>
    </client>

.Net(C#)访问X509证书加密的Webservice(四)--客户端访问WCF,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。