【问题标题】:Consume Web Service with soap:mustUnderstand attribute使用带有 soap:mustUnderstand 属性的 Web 服务
【发布时间】:2018-07-09 15:15:00
【问题描述】:

这是我的 Web 服务示例代码。如果有人可以在这里发现任何问题,我是 SOAP 应用程序的新手,非常感谢。仅当 mustUnderstand attribute ="1" 时才会发生此错误

  [WebService(Namespace = "http://www.xxxx.co.uk/Integration/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class ADNHeaderContact : System.Web.Services.WebService
    {

        public MyHeader myHeader;


        [WebMethod]
        [SoapHeader("myHeader")]

        public string HelloWorld()
        {

            XmlDocument xmlSoapRequest = new XmlDocument();
            using (Stream receiveStream = HttpContext.Current.Request.InputStream)
            {
                receiveStream.Position = 0;
                using (StreamReader readStream =
                                       new StreamReader(receiveStream, Encoding.UTF8))
                {
                    xmlSoapRequest.Load(readStream);
                }
            }


            using (XmlBreaker readxml = new XmlBreaker())
            {
                using (ReponseSaveApplications respose = new ReponseSaveApplications())
                {

                    return ("Hello");


                }

            };
        }

    }

我的邮递员发帖请求

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
     <MyHeader soap:mustUnderstand="true" xmlns="http:www.xxxx.co.uk/Integration/">
      <MyValue>string</MyValue>
    </MyHeader>
  </soap:Header
  <soap:Body>
    <HelloWorld xmlns="http://www.xxxx.co.uk/Integration/" />
  </soap:Body>
</soap:Envelope>

我的邮递员回复

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:MustUnderstand</faultcode>
            <faultstring>System.Web.Services.Protocols.SoapHeaderException: SOAP header MyHeader was not understood.
   at System.Web.Services.Protocols.SoapHeaderHandling.SetHeaderMembers(SoapHeaderCollection headers, Object target, SoapHeaderMapping[] mappings, SoapHeaderDirection direction, Boolean client)
   at System.Web.Services.Protocols.SoapServerProtocol.CreateServerInstance()
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>

【问题讨论】:

    标签: c# xml soap


    【解决方案1】:

    SoapHeader.MustUnderstand Property

    当 XML Web 服务客户端将 SOAP 标头添加到 XML Web 将 MustUnderstand 属性设置为 true 的服务方法调用, XML Web 服务方法必须将 DidUnderstand 属性设置为 true; 否则,将 SoapHeaderException 抛出回 XML Web 服务 ASP.NET 客户端。

    【讨论】:

      猜你喜欢
      • 2015-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      • 2013-03-16
      • 1970-01-01
      相关资源
      最近更新 更多