The*_*dge 9 c# wcf soap web-services
我正在使用我无法访问的WSDL来访问WCF服务,无法修改.对于其中一个请求远程服务正在死亡,因为我们正在发送:
<Action s:mustUnderstand="1"....>
Run Code Online (Sandbox Code Playgroud)
广泛搜索后,我无法找到解决问题的简单方法.所以,在一个典型的消息中:
<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">
Run Code Online (Sandbox Code Playgroud)
我想我可以删除此节点作为消息检查器的一部分:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,即使删除了所有元素后aRequest.Headers.UnderstoodHeaders为空,我仍然看到在XML中发出了Action节点.
答案最终非常简单。
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;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
代替
[System.ServiceModel.OperationContractAttribute(Action ="", ReplyAction="*")]
Run Code Online (Sandbox Code Playgroud)
经过
[System.ServiceModel.OperationContractAttribute(Action ="*", ReplyAction="*")]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3603 次 |
| 最近记录: |