使用soap:mustUnderstand属性消费Web服务

时间:2018-07-09 15:15:01

标签: c# xml soap

这是我的Web服务示例代码。如果有人可以在这里发现任何问题,我是SOAP应用程序的新手,对此深表感谢。仅当mustUnderstand属性=“ 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>

1 个答案:

答案 0 :(得分:1)

  

SoapHeader.MustUnderstand Property

     

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