【发布时间】:2021-12-29 03:34:54
【问题描述】:
我正在开发一个使用 SOAP WCF WS-Addressing 消息与旧系统通信的客户端。
此外,还需要使用包含自定义信息的 To 和 Action 标头自定义 SOAP-Envelope 标头。
我可以通过使用OperationContextScope 来设置To 和Action SOAP-Envelope 标头,如下代码所示:
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?
【问题讨论】:
-
我实际上已经按照这些链接编写了解决方案。我面临的问题是,请求中显然有两个带有
Action的标头,而且它们恰好具有相同的namespace。我试图找到的是如何为这些标题中的任何一个更改这些命名空间。
标签: c# wcf soap ws-addressing