2012-03-14 7 views
1

シナリオは次のとおりです。SOAPメッセージを仲介ルータサービスに送信しようとしています。そのサービスは自分のSOAPメッセージヘッダーだけを気にし、WS-AddressingToヘッダーを使用してメッセージに転送します。MessageHeaders.Toフィールドの設定が上書きされる

私は基本的にルータのサービスに次のような要求をPOSTする必要があり

:私は問題なくCustom Behaviorsを使用してルーティング・サービスが必要で、他のカスタムヘッダーを設定することができ、現在よ

POST http://gatewayRouter/routingService HTTP/1.1 
Content-Type: application/soap+xml; charset=utf-8 
Host: gatewayRouter 
Content-Length: 8786 
Expect: 100-continue 
Connection: Keep-Alive 

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" 
    xmlns:a="http://www.w3.org/2005/08/addressing"> 
<s:Header> <!-- ... --> 
<a:To s:mustUnderstand="1">http://actualDestination</a:To> 
</s:Header> <!-- ... body, /envelope, etc ---> 

を:

public object BeforeSendRequest(ref Message request, IClientChannel channel) 
{ 
    MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue); 
    request = buffer.CreateMessage(); 
    request.Headers.To = new Uri("http://actualDestination"); 
    request.Headers.Add(new CustomHeader()); 
    return null; 
} 

上記のコードは、CustomHeaderをメッセージに追加するのにうまく動作しますが、発信WS-Addressing Toフィールドを変更できません。常にHTTP POST値と同じURIに設定されます。実際、.NET Reflectorを使用して、このフィールドが設定されたときにデバッグしました。十分に上書きされています(screenshot of the stack trace and breakpoint)。

私が正しく理解していないTo SOAPヘッダーを変更する他の方法はありますか?

答えて

0

私はhint from hereと私自身でそれを考え出しました。プログラム的にはcustom behaviorClientRuntimeViaを設定することができます。これにより、WSHttpBindingを使用するためにPOSTが自動的に設定される実際のエンドポイントアドレスと異なることがあります。

public void ApplyClientBehavior 
    (ServiceEndpoint endpoint, ClientRuntime clientRuntime) 
{ 
    CustomMessageInspector inspector = new CustomMessageInspector(); 
    clientRuntime.MessageInspectors.Add(inspector); 
    clientRuntime.Via = new Uri("http://gatewayRouter/routingService"); 
} 
関連する問題