我正在开发一个使用 SOAP WCF WS-Addressing 消息与遗留系统通信的客户端。
此外,还需要使用包含自定义信息的标头来自定义 SOAP-Envelope 标头To
。Action
我能够通过使用如下代码所示的信息To
来设置 SOAP-Envelope 标头:Action
OperationContextScope
public async Task<getAttorneyResponseStructure> GetAttorneyAsync(GetAttorneyRequestStructure getAttorneyRequestStructure)
{
try
{
using (new OperationContextScope(Client.InnerChannel))
{
getAttorneyRequestStructure.AttorneyHeader = Header;
OperationContext.Current.OutgoingMessageHeaders.To = new Uri("http://rydwvgsn01.spga.gov.sa/GSBExpress/Legal/MOJAttorneyInquiry/2.0/AttorneyInquiryService.svc");
OperationContext.Current.OutgoingMessageHeaders.Action = "http://tempuri.org/IAttorneyInquiryService/GetAttorney";
return await Client.GetAttorneyAsync(getAttorneyRequestStructure);
}
}
catch (Exception e)
{
throw;
}
}
当我运行代码并尝试发送消息时,我最终遇到了异常Multiple headers with name 'Action' and namespace 'http://schemas.microsoft.com/ws/2005/05/addressing/none' found.
通过查看图片中附加的异常堆栈,似乎有一个对象包含我要添加的标头的相同信息。
所以,我的问题是有没有改变Action
标题的命名空间或修改Action
包含集合命名空间的现有工作?