I have a BizTalk 2013 app (not R2) that needs to send a Json document to an external vendor's RESTful api. The vendor requires three Http headers:
Content-Type: application/json
Date: in ISO8601 UTC format
Authorization: custom auth. using a constructed string that includes the above Date value run through the HMACSHA1 hash
In BizTalk, my outbound (xml) message goes to the Send Port, there is a Custom Pipeline Component that transforms to Json using JSON.Net. So far, so good. To add the headers which are unique per message, I created a WCF Behavior extension that implements IClientInspector and IEndpointBehavior. In BeforeSendRequest(), I get a reference to the HttpRequestMessageProperty for the request.
I can successfully add to the Headers Collection a ContentType header and an Authorization header. I cannot add a Date header - no errors, just no header value when examining with Fiddler.
I read somewhere that Date is a restricted header and for a workaround I could use Reflection to get around it. E.g.
MethodInfo priMethod = headers.GetType().GetMethod("AddWithoutValidate", BindingFlags.Instance | BindingFlags.NonPublic);
priMethod.Invoke(headers, new[] { "Date", ISODateTimestamp });
That didn't work either. I'm really stumped with: 1. Why no Date header at all is on my request? 2. If there was one, how I could manipulate it as I need to give that is "restricted"?
I tried two different options: a WCF behavior extension:
public object BeforeSendRequest(ref Message request, System.ServiceModel.IClientChannel channel)
{
System.Diagnostics.Debug.Print("Entering BeforeSendRequest()");
try
{
HttpRequestMessageProperty httpRequest = null;
if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name))
{
httpRequest = request.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
}
WebHeaderCollection headers = httpRequest.Headers;
headers.Add(HttpRequestHeader.ContentType, "application/json");
headers.Add(string.Format("{0}:{1}", "Date", _taxwareHelper.ISODateTimestamp));
headers.Add("tweDate", _taxwareHelper.ISODateTimestamp);
headers.Add(HttpRequestHeader.Authorization, _taxwareHelper.AuthorizationString);
and a Custom Pipeline Component in a Send Pipeline
string httpHeaderValue =
new StringBuilder()
.Append("Content-Type: application/json")
.Append("\n")
//.Append(string.Format("Date:{0}", taxwareHelper.ISODateTimestamp))
//.Append("\n")
.Append(string.Format("Date:{0}", "Fri, 10 Jul 2015 08:12:31 GMT"))
.Append("\n")
.Append(string.Format("tweDate:{0}", taxwareHelper.ISODateTimestamp))
.Append("\n")
.Append(string.Format("Authorization:{0}", taxwareHelper.AuthorizationString))
.ToString();
pInMsg.Context.Write("HttpHeaders", "http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties", httpHeaderValue);
in either case, I can set the Content-Type, the Authorization and test date - tweDate just to test, but I can not set the actual Date header.