SecurityVersion.WSSecurityJan2004不支持标头加密

时间:2019-04-05 17:25:50

标签: c# wcf soap

我很想调用Web服务,该服务需要使用证书进行认证,但是当调用GetData方法时,我得到了这个奖励

SecurityVersion.WSSecurityJan2004不支持标头加密。配置名称为“ enterpriseContext”和名称空间为“ B2B_client”的标头进行加密。考虑使用SecurityVersion.WsSecurity11及更高版本,或使用传输安全性对完整邮件进行加密。

代码:

ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
               | SecurityProtocolType.Tls11
               | SecurityProtocolType.Tls12
               | SecurityProtocolType.Ssl3;
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
            delegate
            {
                return true;
            });

            B2BServiceReference.B2BManagerClient client = new B2BServiceReference.B2BManagerClient();

            var objApplicationContext = new B2BServiceReference.EnterpriseContext_Type
            {
                applicationContext = new B2BServiceReference.ApplicationContext()
                {
                    languageCode = B2BServiceReference.ApplicationContextLanguageCode.en,
                    msgUID = "w81d4a669874",
                    version = B2BServiceReference.ApplicationContextVersion.Item10,
                }
            };
            var objGetData = new GetDataRequest();

            objGetData.accountNum = "0101000256001";
            string responseMsg;
            string numberOfReq;

            client.ClientCredentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(@"Testingkeys.pfx", "12345678", X509KeyStorageFlags.UserKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

            client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(@"Testingkeys.pfx", "12345678", X509KeyStorageFlags.UserKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

            var response = client.GetData(ref objApplicationContext, objGetData, out responseMsg, out numberOfReq, out objInquireAccountBalanceResponseAccountBalance, out objBusinessException);

网络配置:

<bindings>
            <customBinding>
                <binding name="B2BManagerBinding">
                  <security authenticationMode="MutualCertificate"
    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" />
                  <textMessageEncoding messageVersion="Soap11" />
                  <httpsTransport />
                </binding>
            </customBinding>
        </bindings>
        <client>
          <endpoint address="https://xxxx" binding="customBinding"
              bindingConfiguration="B2BManagerBinding" contract="B2BServiceReference.B2BManager"
              name="B2BManager" behaviorConfiguration="CustomBehavior">
            <identity>
              <dns value="xxx"/>
            </identity>
          </endpoint>
        </client>
        <behaviors>
        <endpointBehaviors>
          <behavior name="CustomBehavior">
            <!--<clientCredentials>
              <clientCertificate findValue="xxx" x509FindType="FindBySubjectName"
                storeLocation="LocalMachine" storeName="My" />

            </clientCredentials>-->
            <clientCredentials>
              <clientCertificate findValue="xxx" x509FindType="FindBySubjectName"
                storeLocation="LocalMachine" storeName="My" />
              <serviceCertificate>
                <defaultCertificate findValue="xxx" x509FindType="FindBySubjectName"
                storeLocation="LocalMachine" storeName="My" />
                <authentication certificateValidationMode="None" />
              </serviceCertificate>
            </clientCredentials>
          </behavior>
        </endpointBehaviors>
      </behaviors>

0 个答案:

没有答案