カスタム SOAP ヘッダーを作成し、IClientMessageInspector を介してメッセージに追加しました
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
var header = new MessageHeader<AuthHeader>();
header.Content = new AuthHeader(Key);
header.Actor = "Anyone";
var header2 = header.GetUntypedHeader("Auth", "xWow");
request.Headers.Add(header2);
return null;
}
[DataContract(Name="Auth")]
public class AuthHeader
{
public AuthHeader(string key)
{
this.Key = key;
}
[DataMember]
public string Key { get; set; }
}
IDispatchMessageInspector もあり、リストで正しいヘッダーを見つけることができます。ただし、値はありません。メッセージ文字列が正しいため、値がネットワークを正しく通過したことがわかります
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Auth s:actor="Anyone" xmlns="xWow" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Key xmlns="http://schemas.datacontract.org/2004/07/xWow.Lib">HERE IS MY KEY VALUE!!!!</Key>
</Auth>
<To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://localhost:26443/AuthService.svc</To>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IAuthService/GetPayload</Action>
</s:Header>
<s:Body>
<GetPayload xmlns="http://tempuri.org/"/>
</s:Body>
</s:Envelope>
しかし、この値を取得するためのプロパティはないようです。MessageHeaderInfo クラスには Actor などがありますが、他に役立つものは何もありません。
クライアント側でヘッダーと型なしヘッダーを変換する必要がありましたが、サーバー上で同等の操作はありますか?
次のものが見つかりました。これは機能するはずです。
request.Headers.FindHeader("Auth", "xWow");
request.Headers.GetHeader<AuthHeader>(index);
適切なインデックスを手動で見つけて 2 行目を呼び出すと、期待どおりに動作します。ただし、ウォッチ ウィンドウで名前と名前空間の正しい値であることを確認したにもかかわらず、FindHeader はインデックスとして -1 を返します。