WSDL C#中的安全标头

问题描述 投票:0回答:1

我必须为WSDL创建客户端。但我不断得到“消息中没有安全标头,但策略必需。”

这是我的代码

            USImportoerService service = new USImportoerService();
            X509Certificate2 cert = new X509Certificate2(certPath, PASSWORD, X509KeyStorageFlags.MachineKeySet);

            service.ClientCertificates.Add(cert);

            var result = ser.getUSKoeretoej();

这里是App.config

<configuration>
<system.serviceModel>
    <bindings>
        <customBinding>
            <binding name="USImportoerService_Port">
              <security authenticationMode="CertificateOverTransport" securityHeaderLayout="LaxTimestampLast" includeTimestamp="true" 
            enableUnsecuredResponse="true">
              </security>
                <textMessageEncoding messageVersion="Soap11" />
                <httpsTransport />
            </binding>
        </customBinding>
    </bindings>
  <client>
        <endpoint address="HTTPS TO WSDL"
            binding="customBinding" bindingConfiguration="USImportoerService_Port"
            contract="ServiceReferenceUSImportoer.USImportoerServiceType"
            name="Port1" />
    </client>
</system.serviceModel>

希望有人可以帮助您

c# .net wsdl
1个回答
0
投票

使用HttpClient调用SOAP服务

   USImportoerService service = new USImportoerService();
   X509Certificate2 cert = new X509Certificate2(certPath, PASSWORD, X509KeyStorageFlags.MachineKeySet);
    HttpClientHandler handler = new HttpClientHandler();
    handler.ClientCertificates.Add(cert);
    HttpClient client = new HttpClient(handler);
    // Call service using httpClient
    //var result = ser.getUSKoeretoej();

如何使用httpClient调用SOAP服务Client to send SOAP request and receive response

© www.soinside.com 2019 - 2024. All rights reserved.