0

Json ドキュメントを外部ベンダーの RESTful API に送信する必要がある BizTalk 2013 アプリ (R2 ではない) があります。ベンダーは、次の 3 つの Http ヘッダーを必要とします。

  1. コンテンツ タイプ: アプリケーション/json

  2. 日付: ISO8601 UTC 形式

  3. 承認:カスタム認証。HMACSHA1 ハッシュを介して実行される上記の Date 値を含む構築された文字列を使用する

BizTalk では、アウトバウンド (xml) メッセージが送信ポートに送信されます。JSON.Net を使用して Json に変換するカスタム パイプライン コンポーネントがあります。ここまでは順調ですね。メッセージごとに固有のヘッダーを追加するために、IClientInspector と IEndpointBehavior を実装する WCF Behavior 拡張機能を作成しました。BeforeSendRequest() で、リクエストの HttpRequestMessageProperty への参照を取得します。

Headers Collection に ContentType ヘッダーと Authorization ヘッダーを正常に追加できます。Date ヘッダーを追加できません。エラーはなく、Fiddler で調べたときにヘッダー値がありません。

Date は制限されたヘッダーであり、回避策として Reflection を使用して回避できることをどこかで読みました。例えば

    MethodInfo priMethod = headers.GetType().GetMethod("AddWithoutValidate", BindingFlags.Instance | BindingFlags.NonPublic);
    priMethod.Invoke(headers, new[] { "Date", ISODateTimestamp });

それもうまくいきませんでした。私は本当に困惑しています: 1. リクエストに Date ヘッダーがまったくないのはなぜですか? 2. ある場合、それを「制限」する必要があるため、どのように操作できますか?

私は 2 つの異なるオプションを試しました: WCF 動作拡張:

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);

および送信パイプラインのカスタム パイプライン コンポーネント

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);

どちらの場合も、Content-Type、Authorization、およびテスト日 (テストするためだけに tweDate) を設定できますが、実際の Date ヘッダーを設定することはできません。

4

1 に答える 1