阅读SOAP Header和Body元素

时间:2014-11-01 09:35:20

标签: c# soap

我想从soap header和SOAP Body中读取元素值。请查看下面的代码并帮助我获取custid和clientid表单标题和正文。如果您需要进一步澄清,请发布给我

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Header>
   <APHeader xmlns="http://www.test.com/es/v1/ws">
    <usr>
    <Verb>Set</Verb>
    <Noun>ProcessEIACMPermissions</Noun>
    <DataVer>001:000</DataVer>
    <SrcAppID xsi:type="xsd:string">AP</SrcAppID>
    <CustID>30081241</CustID>
    <APMsgCorrelationID>00000000000000000000000000000000</APMsgCorrelationID>
    </usr>
  </APHeader>
  </soap:Header>
  <soap:Body>
    <ProcessEIACMPermissionsRequest      xmlns="http://www.adp.com/es/ezlm/v1/schema/tlmclientconfiguration">
    <ClientID>30081241</ClientID>
  </ProcessEIACMPermissionsRequest>
 </soap:Body>

2 个答案:

答案 0 :(得分:0)

我找到了这样做的简单方法。只需从httprequest读取输入流,加载xml并从xml获取CustID。以下是相同的代码。

 var httpApp = sender as HttpApplication;
            var Request = httpApp.Request as HttpRequest;
            string documentContents;
            using (Stream receiveStream = Request.InputStream)
            {
                using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
                {
                    documentContents = readStream.ReadToEnd();
                }
            }            
            XmlDocument xd = new XmlDocument();
            xd.LoadXml(documentContents);
            XmlElement root = xd.DocumentElement;
            XmlNodeList titleList = root.GetElementsByTagName("CustID");
            return titleList[0].InnerText;         

答案 1 :(得分:0)

case SoapMessageStage.BeforeSerialize:
                break;
            case SoapMessageStage.AfterSerialize:

                break;
            case SoapMessageStage.BeforeDeserialize:
                break;
            case SoapMessageStage.AfterDeserialize:
                foreach (SoapHeader header in message.Headers)
                {
                    if (header.GetType() == typeof(RouteInformation))
                    {
                        routeHdr = (RouteInformation) header;
                        if(!string.IsNullOrEmpty(routeHdr.ConsumerID))
                            id = DataFix.FixInt(routeHdr.ID);
                    }
                    else if (header.GetType() == typeof (Header))
                    {
                        Hdr = (Header) header;
                        Custid = DataFix.FixInt(Hdr.m_objUsr.ID);

                    }
                    else if(header.GetType() == typeof(Configuration))
                    {
                        configHdr = (ConfigurationAPHeader) header;

                    }
                }