【问题标题】:Consuming wsdl using c# but getting error: "SOAP header To was not understood "使用 c# 使用 wsdl 但出现错误:“无法理解 SOAP 标头”
【发布时间】:2011-10-10 12:18:06
【问题描述】:

我正在使用 c# 使用 wsdl,但我收到以下错误 “无法理解 SOAP 标头 To”。

是什么导致了这个问题,我该如何解决?


感谢您的回复, 根据您的建议,我尝试了以下代码:

 using System;
 using System.Collections.Generic;
 using System.Web;
 using System.Web.Services; 
 using System.Web.Services.Protocols; 

 [WebService(Namespace = "http://tempuri.org/")]
 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

 public class MyHeader : SoapHeader
 {


 public bool _MustUnderstand;

public MyHeader() { }

public bool MustUnderstand
{
    get { return _MustUnderstand; }
    set { _MustUnderstand = value; }
 }

} 



public class Service : System.Web.Services.WebService
{
 public MyHeader MustUnderstand; 
public Service () 
{

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
}

[WebMethod]
[SoapHeader("MustUnderstand")]
public void Nokia()
{
    MustUnderstand = new MyHeader();
    MustUnderstand.MustUnderstand = true; 

    WebService connect = new WebService();

    long publicKeyK ;
    publicKeyK=        connect.GetPublicKey(out publicKeyK); 
}   

}

(我在 mustUnderstand 属性上也设置了 false ...)

我仍然收到相同的错误消息。 “无法理解 SOAP 标头 To”

有什么想法吗? 波利。

【问题讨论】:

    标签: soap


    【解决方案1】:

    每当您收到“SOAP 标头 X 未被理解”时,这意味着该元素的 MustUnderstand 属性已设置为 true,并且使用应用程序无法“理解”或识别该元素。发送消息的应用程序可能正在设置 MustUnderstand 属性,因为我认为默认情况下它未设置或为 false。 见http://msdn.microsoft.com/en-us/library/system.servicemodel.messageheaderattribute.aspx

    【讨论】:

    • 这个答案对我有很大帮助。要从响应消息中删除MustUnderstand,您必须编写自己的SoapFilter,并覆盖SoapFilterResult ProcessMessage(SoapEnvelope envelope)。在这里,您可以访问原始 xml 并删除您想要的任何属性。然后,您创建自己的派生自 SecurityPolicyAssertion 的类,并在 SoapFilter CreateClientInputFilter(FilterCreationContext context) 中使用您的过滤器。
    猜你喜欢
    • 2010-09-19
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 2015-02-23
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多