We are using a SOAP adapter with Basic Authentication. The same issue will however occur with WCFWebHttp adapter as well. On checking further in fiddler traces we found out that the server is sending the following response:

Here is the catch. The reason why were not able to send is that the server was returning the error code as 500, which means Internal server error. Therefore BizTalk client will never come to know that the server is expecting the authentication information and therefore the handshake fails.

The solution can be to send the basic authentication information in the first request itself. This means that we want to eliminate the handshake and server is not required to send a 401 request.

This method can be called from the expression shape and then the response can be send back to BizTalk for further processing. Once the above code is implemented the outgoing message will look something like this: