4

Wanting to communicate with a SOAP webservice, I had C# classes created by SvcUtil.exe from the wsdl file.

When sending the Request below to a secure server (HTTPS with BASIC auth) I receive a System.ServiceModel.Security.MessageSecurityException and when checking the HTTP request by having traffic go though a Burp proxy I see that no BASIC auth information is passed. Is anything missing for the SOAP request in the C# code or what could be the problem that the BASIC auth does not work?

var binding = new WSHttpBinding();
binding.MessageEncoding = WSMessageEncoding.Mtom;

binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.Name = "BasicAuthSecured";

SearchServicePortClient searchClient = new SearchServicePortClient(binding,  new EndpointAddress("https://myUrl:Port/myService"));
searchClient.ClientCredentials.UserName.UserName = "username";
searchClient.ClientCredentials.UserName.Password = "pw";

query soap = new query();
//...

queryResponse response = searchClient.query(soap);

Thanks in advance

2 Answers 2

2

This is another approach, don't know if it is the best though

using (var client = _clientFactory.GetClient())
{
    var credentials = Utils.EncodeTo64("user123:password");
    client.ChannelFactory.CreateChannel();
    using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
    {
        var httpRequestProperty = new HttpRequestMessageProperty();
        httpRequestProperty.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
        //operation
        client.Send(request);
    }
}
0

Try to use TransportWithMessageCredential:

binding.Security.Mode = SecurityMode.TransportWithMessageCredential;
1
  • Sorry, I don't remember it was 3 years ago. Commented Jan 29, 2020 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.