Recently one of my customer was getting the following error when trying to send messages to a service:
A message sent to adapter “SOAP” on send port “sndPrt_zzzzz” with URI “https://xxx.com/yyy” is suspended.
Error details: 320 – Security Error
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:
HTTP/1.1 500 Authentication Required
Date: Fri, 27 Feb 2015 23:02:02 GMT
Accept: text/html, application/xhtml+xml, */*
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
WWW-Authenticate: Basic realm=”xxxx.com”
X-P2P-PeerDistEx: MinContentInformation=1.0, MaxContentInformation=2.0
Content-Type: text/xml; charset=”UTF-8″
Ideally the message handshake with basic authentication happens as follows:
Client -> Sends request ->Server
Server -> 401 Unauthorized -> Client
Client -> Authentication -> Server
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.
How can this be done in BizTalk Server?
Answer is; we cannot.
Sending a message with pre-authorization will not be possible using any adapter in BizTalk. As per this msdn link, https://msdn.microsoft.com/en-us/library/aa547980(BTS.20).aspx.
It mentions that we can set some custom headers but authentication header is not allowed.
Therefore the workaround will be to send the message to the web service using a C# library. Here is the code snippet that can help you send the pre-authorized messages to the server side.
public static void CallWebRequest(string message)
//Set the URL of the service and creating a request object
string url = https://xxxx.com/yyyyy;
HttpWebRequest req = HttpWebRequest.Create(url) as HttpWebRequest;
//Specifying the logon information
string user = “UserName”;
string pwd = “Password”;
//Adding the Basic Authentication information to the header
string auth = “Basic ” + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(user + “:” + pwd));
req.PreAuthenticate = true;
req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
//writing the message body to the request
byte bytes = Encoding.UTF8.GetBytes(message);
req.Method = “POST”;
req.ContentType = “text/xml; encoding=’utf-8′”;
req.ContentLength = bytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
//updating action and sending the response
string action = http://xxxx.com/yyyy;
req.UserAgent = “zzzzzzzz”;
WebResponse resp = req.GetResponse();
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:
Authorization: Basic aaaaaaaaaaaaaaaaaaaaaaaaaaaaa==
Content-Type: text/xml; encoding=’utf-8′
Hope this will save some time for you… !!!