【问题标题】:SOAP WCF WS-Addressing 'Multiple headers with name 'Action' and namespace 'http://schemas.microsoft.com/ws/2005/05/addressing/none' found.'SOAP WCF WS-Addressing '找到名称为 'Action' 和命名空间 'http://schemas.microsoft.com/ws/2005/05/addressing/none' 的多个标头。
【发布时间】:2021-12-29 03:34:54
【问题描述】:

我正在开发一个使用 SOAP WCF WS-Addressing 消息与旧系统通信的客户端。

此外,还需要使用包含自定义信息的 ToAction 标头自定义 SOAP-Envelope 标头。

我可以通过使用OperationContextScope 来设置ToAction 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

【问题讨论】:

  • 您可以阅读这些文章以找到解决方案stackoverflow.com/questions/9129750/…docs.microsoft.com/en-us/dotnet/api/…
  • 我实际上已经按照这些链接编写了解决方案。我面临的问题是,请求中显然有两个带有Action 的标头,而且它们恰好具有相同的namespace。我试图找到的是如何为这些标题中的任何一个更改这些命名空间。

标签: c# wcf soap ws-addressing


【解决方案1】:

解决了! 事实证明,我使用默认 BasicHttpBinding 的问题是使用与服务器不同的不同肥皂版本。此外,不需要标头中的Action 属性,因为我在连接构造函数中使用CustomBinding 更改了SOAP 版本,如下所示:

CustomBinding binding = new CustomBinding();

var mtomMessageEncodingBindingElement = new MtomMessageEncodingBindingElement
{
  MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10),
};
binding.Elements.Add(mtomMessageEncodingBindingElement);

var httpTransportBindingElement = new HttpTransportBindingElement();
binding.Elements.Add(httpTransportBindingElement);
            
Client = new AttorneyInquiryServiceClient(binding, new EndpointAddress("http://rydwvgsn01.spga.gov.sa/GSBExpress/Legal/MOJAttorneyInquiry/2.0/AttorneyInquiryService.svc"));

对上面代码的一些补充说明:

  • MtomMessageEncodingBindingElement:用于设置SOAP版本的版本,并启用MOTM类型的响应。

  • HttpTransportBindingElement:绑定中需要。

  • 在方法调用中,Action被移除了。

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");

      return await Client.GetAttorneyAsync(getAttorneyRequestStructure);
    }
  }
  catch (Exception e)
  {
   throw;
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多