0
発信SOAP要求にデータを追加し、クライアントサービスのエンドポイントの動作として追加するClientInspectorを作成しようとしています。このような何か:.NETでSOAPメッセージヘッダー要素の名前空間を明示的に設定する方法
public class InsertHeaderClientInspector : IClientMessageInspector
{
public object BeforeSendRequest(ref Message request, System.ServiceModel.IClientChannel channel)
{
var HeaderData = new ProcType()
{
attr = _correlation
};
MessageHeader header = MessageHeader.CreateHeader("HeaderInfo", "http://schemas.tempuri.fi/process/2016/04/", HeaderData);
request.Headers.Add(header);
return null;
}
}
[System.Xml.Serialization.XmlRootAttribute("HeaderInfo", Namespace = "http://schemas.tempuri.fi/process/2016/04/", IsNullable = false)]
public class ProcType
{
[XmlElement(Namespace = "")]
public string attr;
}
Inspectorは正常に動作しているが、問題が発生したSOAPメッセージがProcType.attrの名前空間を持つことになりますし、私はそれを削除することです。
<s:Header>
<HeaderInfo xmlns="http://schemas.tempuri.fi/process/2016/04/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<attr xmlns="http://schemas.datacontract.org/2004/07/MyService.Behaviors">asdasd</attr>
</HeaderInfo>
</s:Header>
代わりに、それは
<s:Header>
<HeaderInfo xmlns="http://schemas.tempuri.fi/process/2016/04/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<attr">asdasd</attr>
</HeaderInfo>
</s:Header>
ようにする必要がありXMLElementの私が使用しようとした属性が動作しません。どうすればこの不要な名前空間を削除できますか?
ここにチェック:http://stackoverflow.com/questions/24305747/how-to-remove-xmlns-attribute-of-a-node-other-than-root-in-an-xdocument – Mike
私はしませんこれが問題を解決すると思う。 CreateHeader()はProcTypeオブジェクトをシリアライズし、名前空間を設定します。ヘッダーの作成後にMessageHeaderを通じてシリアル化されたXMLオブジェクトにアクセスすることはできません。 –