使用IClientMessageInspector从WCF soap请求中删除动作节点mustUnderstand
本文关键字:删除 节点 mustUnderstand 请求 IClientMessageInspector WCF soap 使用 | 更新日期: 2023-09-27 18:01:59
我正在使用我无法访问且无法修改的WSDL访问WCF服务。对于其中一个请求,远程服务正在死亡,因为我们正在发送:
<Action s:mustUnderstand="1"....>
经过广泛的搜索,我找不到一个简单的解决问题的方法。所以,在一个典型的消息中:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<retrieveBooking xmlns="http://services.rccl.com/Interfaces/RetrieveBooking">
<OTA_ReadRQ TransactionActionCode="RetrievePrice" SequenceNmbr="1" Version="1" xmlns="http://www.opentravel.org/OTA/2003/05/alpha">
我想我可以删除这个节点作为消息检查器的一部分:
internal class MyMessageInspector : IClientMessageInspector
{
public object BeforeSendRequest(ref Message aRequest, IClientChannel aChannel)
{
//Get rid of mustUnderstand Action node
foreach (MessageHeaderInfo headerInfo in aRequest.Headers.UnderstoodHeaders)
{
aRequest.Headers.UnderstoodHeaders.Remove(headerInfo);
}
return null;
}
}
然而,即使在我删除所有元素后arequest . headers . underoodheaders是空的,我仍然看到Action节点在XML中发出。
- 我要怎么做才能使它工作?
- 我怎么到达的第一个节点的名称正文标签retrieveBooking在这种情况下?我只需要做
答案其实很简单。
public object BeforeSendRequest(ref Message aRequest, IClientChannel aChannel)
{
//For the CabinDetail message the API provider has requested that we REMOVE the XML action node from the header as it causes their end to fail
//<s:Header>
//<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
//</s:Header>
if (aRequest.ToString().Contains("CabinDetail"))
{
int headerIndexOfAction = aRequest.Headers.FindHeader("Action", "http://schemas.microsoft.com/ws/2005/05/addressing/none");
aRequest.Headers.RemoveAt(headerIndexOfAction);
}
return null;
}
Replace
[System.ServiceModel.OperationContractAttribute(Action ="", ReplyAction="*")]
[System.ServiceModel.OperationContractAttribute(Action ="*", ReplyAction="*")]