2011-07-27 3 views
0

API의 데이터를 사용하려했지만 XML 응답을 읽을 수 없었습니다.C#을 사용하여 SOAP 응답 구문 분석

<?xml version="1.0" standalone="no"?> 
     <SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
     <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
      <SOAPSDK4:GetStoreProductsResponse xmlns:SOAPSDK4="http://www.externalwebservice.com/message/"> 
       <StoreProducts> 
        <StoreID></StoreID> 
        <Products></Products> 
       </StoreProducts> 
      </SOAPSDK4:GetStoreProductsResponse></SOAP-ENV:Body> 
     </SOAP-ENV:Envelope> 

을 그리고 내가 필요한 것은 (지금은) 제품 안에 무엇인가 :

그것은 형태로 cames.

나는 결과없이 Using C# to parse a SOAP Response (및 다른 사람은이 문제를 범하지 않기 위해)을 사용하려고 시도하고있었습니다.

내 코드 :

XDocument tst = XDocument.Load("Response.xml"); 
    XNamespace xmlns = "http://schemas.xmlsoap.org/soap/envelope/"; 
    var tstr = from result in tst.Descendants(xmlns + "StoreProducts") select result.Element("Products").Value; 

나는 기본적인 뭔가를 놓친 것을 거의 확신합니다.

실마리가 될 것입니다.

감사합니다. 내부 XML이처럼 보였다 경우

var tstr = from result in tst.Descendants("StoreProducts") 
      select result.Element("Products").Value; 

당신이 준 예제 코드가 성공했을 :

<SOAP-ENV:StoreProducts> 
    <StoreID></StoreID> 
    <Products></Products> 
    </SOAP-ENV:StoreProducts> 
+0

에 전송 된 XML을 읽을 필요? http://stackoverflow.com/questions/2876012/using-c-to-parse-a-soap-response – Peyman

답변

1

은 수행하는 XML 네임 스페이스 내에 있지 XML을 구문 분석해야합니까? .NET은 C# 프록시를 사용하여 SOAP을 처리하는 데 매우 효율적입니다.

svcutil.exe를 사용하여 프록시를 생성 한 적이 있습니까? 내 경우

+0

감사합니다. 이것은 내가 필요한 방식으로 효과가있었습니다. – Elder

1

이 있습니까 당신의 XML StoreProducts에서

0

난 당신이 링크를 확인 했 POST 요청

 // read the raw request 
     Request.InputStream.Seek(0, SeekOrigin.Begin); 
     string xmlPayload = new StreamReader(Request.InputStream).ReadToEnd(); 
     XDocument doc = XDocument.Parse(xmlPayload); 

     XNamespace xmlns = "urn:sobject.enterprise.soap.sforce.com"; 
     item.sfId = doc.Descendants(xmlns + "Id").First().Value; 
     item.AccountId = doc.Descendants(xmlns + "AccountId").First().Value; 
     item.FirstName = doc.Descendants(xmlns + "FirstName").First().Value; 
     item.LastName = doc.Descendants(xmlns + "LastName").First().Value; 
     item.XmlPayload = xmlPayload;