2012-04-25 6 views
3

이 포럼 및 다른 포럼을 몇 시간 동안 읽고 있었으며 비누 응답에 대한 해결책을 찾을 수 없습니다. 여기 답변의 모든 종류를 시도하고, 그러나 나의 응답을 :(구문 분석 할 수 없습니다monodevelop parse soap response

내 응답 :

<?xml version="1.0" encoding="utf-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
     <getLocationsResponse xmlns="http://getlocations.ws.hymedis.net"> 
      <locs> 
       <loc> 
        <name>Zeebrugge Wielingen Zand</name> 
        <abbr>ZWZ</abbr> 
        <RDX>1435.8</RDX> 
        <RDY>378678.6</RDY> 
        <params> 
         <param>GHs</param> 
         <param>SS10</param> 
        </params> 
       </loc> 
      </locs> 
     </getLocationsResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

내 C# 코드는 지금까지 (PARAM의 soapresponse 문자열 형식의 전체 soapresponse입니다) 내 대답은 > 그래서 그 (것)들에있는 데이터가 .. PLZ 날 도와하지

답변

2

- 올바른 전체 XML 비누 응답 있도록,하지만 좋은

public void readXml(string soapresponse){ 
     XmlDocument xmlresponse = new XmlDocument(); 
     xmlresponse.LoadXml(soapresponse); 

     XmlNamespaceManager nsmanager = new XmlNamespaceManager(xmlresponse.NameTable); 
     nsmanager.AddNamespace ("soapenv", "http://schemas.xmlsoap.org/soap/envelope/"); 

     XmlNodeList nodes = xmlresponse.SelectNodes("/soapenv:Envelope/soapenv:Body/getLocationsResponse/locs/loc", nsmanager); 
     List<Locatie> locatielijst = new List<Locatie>(); 
     // loop 
     foreach(XmlNode node in nodes){ 
      string loc_naam = node["name"].InnerText; 
      string loc_code = node["abbr"].InnerText; 
      ... 
      Locatie locatie = new Locatie(); 
      locatie.loc_naam = loc_naam; 
      locatie.loc_code = loc_code; 
      ... 
      locatielijst.Add (locatie); 
     } 

     Console.WriteLine(locatielijst.Count.ToString()); 
     foreach(Locatie loc in locatielijst){ 
      Console.WriteLine (loc.loc_code); 
     } 

    } 

하지만 내 list.count는 0을 반환 할 때마다이 구문 분석 할 수 없습니다!다음 코드가 작동 할 수 있습니다.

 
    public class MainClass 
    { 
     public static void Main(string[] args) 
     { 
      var response = new FileStream("Response.xml", FileMode.Open); 

      XDocument doc = XDocument.Load(response); 
      XNamespace xmlns = "http://getlocations.ws.hymedis.net"; 

      var nodes = doc.Descendants(xmlns + "locs") 
           .Elements(xmlns + "loc"); 

      var list = new List(); 
      foreach (var node in nodes) 
      { 
       list.Add(new Location { 
        Name = node.Element(xmlns + "name").Value, 
        Code = node.Element(xmlns + "abbr").Value 
       }); 
      } 

      foreach (var item in list) { 
       Console.WriteLine(item.Code); 
      } 
     } 

     public class Location 
     { 
      public string Code { get; set; } 
      public string Name { get; set; } 
     } 
    } 

모노에 대한 많은 경험이 없지만 .net은 WCF SOAP 서비스를 매우 쉽게 사용하도록 만들었습니다. 이 문서에서는 WCF 서비스의 프록시 클래스를 생성하는 방법을 설명합니다. http://johnwsaunders3.wordpress.com/2009/05/17/how-to-consume-a-web-service/

이 정보가 도움이되기를 바랍니다.

감사합니다. Wouter Willaert