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>
  • 相关阅读:
    python BUGGGGGGGGGG
    Golang channel底层原理及 select 和range 操作channel用法
    Go reflect包用法和理解
    Golang 之sync包应用
    Golang 之 sync.Pool揭秘
    深入理解字节码文件
    java中的回调,监听器,观察者
    范式
    BIO,NIO,AIO总结(二)
    anaconda命令行运行过程中出现的错误
  • 原文地址:https://www.cnblogs.com/batter152/p/3622626.html
Copyright © 2011-2022 走看看