I am trying to consume a third-party SOAP web service in my C# console app. I tried two different way of passing the credentials as shown below.
//Method 1 - passing security credentials
myCardService.Credentials = new System.Net.NetworkCredential("username",
"password");
//Method 2 - passing security credentials
System.Net.CredentialCache myCredentials = new System.Net.CredentialCache();
NetworkCredential netCred = new NetworkCredential("username", "password");
myCredentials.Add(new Uri(myCardService.Url), "Basic", netCred);
myCardService.Credentials = myCredentials;
In both the cases, I am getting this exception:
System.Web.Services.Protocols.SoapHeaderExceptions: Error in SecurityHeader: An Invalid security token was provided
When I tried SOAP UI to consume the service, there also I got the same error. However, when I made WSS-Password Type = PasswordText in the Properties window of the tool, then it worked. I don't see any way to make this setting in the credential objects in the C# code. Any help is greatly appreciated.
The issue was resolved after I installed WSE 3.0 from https://www.microsoft.com/en-us/download/details.aspx?id=14089 and changed the web reference manually from System.Web.Services.Protocols.SoapHttpClientProtocol to Microsoft.Web.Services3.WebServicesClientProtocol in the Reference.cs file.