• .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>
  • 相关阅读:
    浅析如何让 (a === 1 && a === 2 && a === 3) 返回 true
    浅析单点登录的三种实现方式
    浅析瀑布流布局原理及实现方式
    浅析Java中三目运算符可能产生的坑
    【转】IO
    [转]gomonkey学习
    从sha1的计算例子,理解计算机的数据表示?16进制输出?二进制输出??
    [转]Golang第三方包应该如何安装--在线和离线
    【转】goconvey使用
    go import 时 点号 和下划线的区别
  • 原文地址:https://www.cnblogs.com/batter152/p/3622626.html
Copyright © 2020-2023  润新知