当名称空间前缀和xmlns前缀不等于

时间:2017-09-27 07:11:54

标签: c# web-services soap

您好我完全卡住了,我可以通过远程service.svc wsdl以某种方式获得响应。抱歉英语不好。 有我的工作样本,感谢 stackoverflow

using System;
using System.Xml;


namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            string responseXml =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<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>" +
                       "<Company xmlns:b=\"http://www.someurl.com/Report/Company\">" +
                                "<b:LoginResult>" +
                                "<b:CookieName>FedAuth</b:CookieName>" +
                                "<b:ErrorCode>NoError</b:ErrorCode>" +
                                "<b:TimeoutSeconds>1800</b:TimeoutSeconds>" +
                                "<b:Parametrs>Zoroo 100</b:Parametrs>" +
                                "</b:LoginResult>" +
                        "</Company>" +
                    "</soap:Body>" +
                "</Envelope>";


            XmlDocument document = new XmlDocument();
            document.LoadXml(responseXml);  //loading soap message as string 
            XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);


            manager.AddNamespace("b", "http://www.someurl.com/Report/Company");



            XmlNodeList xnList = document.SelectNodes("//b:LoginResult", manager);
            int nodes = xnList.Count;

            foreach (XmlNode xn in xnList)
            {
                string CookieName = xn["b:CookieName"].InnerText;
                string ErrorCode = xn["b:ErrorCode"].InnerText;
                string TimeoutSeconds = xn["b:TimeoutSeconds"].InnerText;
                string Parametrs = xn["b:Parametrs"].InnerText;

                Console.WriteLine();
                Console.WriteLine(CookieName + ErrorCode + TimeoutSeconds + Parametrs);
                Console.WriteLine();


            }


        }
    }

}

我的问题是,当我收到这样的消息时,我无法理解肥皂响应消息:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <GCRResponse xmlns="http://www.someurl.com/Report">
         <GCRResult xmlns:a="http://www.someurl.com/CReport" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

        <a:Company xmlns:b="http://www.someurl.com/Company">
                  <b:General>
                  <b:SomeInfo xmlns:c="http://www.someurl.com/Report/Common">
                     <c:Curr>BUM</c:Curr>
                     <c:LocalValue>1.00</c:LocalValue>
                     <c:Value>1.00</c:Value>
                  </b:SomeInfo>
                  <b:BS>Active</b:BS>
                  <b:CName>Zabis</b:CName>
                  <b:ES>NotSpecified</b:ES>
                  <b:NACELookup>
                     <a:NACE>NotSpecified</a:NACE>
                  </b:NACELookup>
                  <b:PC xmlns:c="http://www.someurl.com/Report/Common">
                     <c:Curr>BUM</c:Curr>
                     <c:LocalValue>1.00</c:LocalValue>
                     <c:Value>1.00</c:Value>
                  </b:PC>
               </b:General>
             </a:Company>
            <a:CompanyRep i:nil="true" xmlns:b="http://www.someurl.com/Report/SomeReport"/>
               <a:Parameters>
               <a:Consent>true</a:Consent>
               <a:IDNumber>30103331133</a:IDNumber>
               <a:IDNumberType>RNumber</a:IDNumberType>
               <a:InquiryReason>Application</a:InquiryReason>
               <a:ReportDate>2017-09-26T08:57:26.6885118+03:00</a:ReportDate>
               <a:Sections xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                  <b:string>SubjectInfo</b:string>
               </a:Sections>
               <a:SubjectType>Company</a:SubjectType>
            </a:Parameters>
               <a:ReportInfo xmlns:b="http://www.someurl.com/Report/ReportInfo">
               <b:Created>2017-09-26T08:57:26.7197686+03:00</b:Created>
               <b:ReferenceNumber>333368-9543457</b:ReferenceNumber>
               <b:ReportStatus>ReportGenerated</b:ReportStatus>
               <b:RequestedBy i:nil="true"/>
               <b:Subscriber i:nil="true"/>
               <b:Version>325</b:Version>
            </a:ReportInfo>
         </GCRResult>
      </GCRResponse>
   </s:Body>
</s:Envelope>

如果我的命名空间具有不同的前缀(a,b)而不是xmlns前缀,例如此处

,那么如何访问值
<a:Company xmlns:b="http://www.someurl.com/Company"> 

manager.AddNamespace a:Company xmlns:b时,我无法弄清楚如何使用a,b,c 如何访问所有值root

0 个答案:

没有答案