zoukankan      html  css  js  c++  java
  • .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>
  • 相关阅读:
    套件测试
    注解实战aftersuite和beforesuite
    注解实战Beforeclass和Afterclass
    Centos7下安装Mongodb
    java的算法实现冒泡
    注解实战BeforeMethed和afterMethed
    前端 HTML的规范
    前端 HTML标签介绍
    前端 HTML文档 详解
    前端 HTML 简介
  • 原文地址:https://www.cnblogs.com/batter152/p/3622626.html
Copyright © 2011-2022 走看看