How can I pass a username/password in the header to a SOAP WCF Service

后端 未结 9 1747
长发绾君心
长发绾君心 2020-11-27 13:03

I\'m trying to consume a third-party web service https://staging.identitymanagement.lexisnexis.com/identity-proofing/services/identityProofingServiceWS/v2?wsdl

I alr

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 13:14

    The answers above are so wrong! DO NOT add custom headers. Judging from your sample xml, it is a standard WS-Security header. WCF definitely supports it out of the box. When you add a service reference you should have basicHttpBinding binding created for you in the config file. You will have to modify it to include security element with mode TransportWithMessageCredential and message element with clientCredentialType = UserName:

    
      
        
          
        
      
    
    

    The config above is telling WCF to expect userid/password in the SOAP header over HTTPS. Then you can set id/password in your code before making a call:

    var service = new MyServiceClient();
    service.ClientCredentials.UserName.UserName = "username";
    service.ClientCredentials.UserName.Password = "password";
    

    Unless this particular service provider deviated from the standard, it should work.

提交回复
热议问题