1
SOAP 메시지를 특정 클래스로 구문 분석하려고하는데 문제가 있습니다.비누 XML을 C# 클래스로 구문 분석합니다.
public class SoapResponse
{
public string CookieName { get; set; }
public int TimeoutSeconds { get; set; }
public string ErrorCode { get; set; }
}
나는 비누 XML을 평가하기 위해 Linq를 사용하고로 구문 분석하려고 해요 : 나는 3 개 속성을 가진 간단한 클래스가 가지고
<?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>
<LoginResponse
xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<LoginResult>
<CookieName>FedAuth</CookieName>
<ErrorCode>NoError</ErrorCode>
<TimeoutSeconds>1800</TimeoutSeconds>
</LoginResult>
</LoginResponse>
</soap:Body>
</soap:Envelope>
:
이
는 SOAP 메시지입니다 SoapResponse 클래스의 객체입니다. 지금까지 나는 다음 코드가 있습니다var xml = XDocument.Parse(responseXml);
var soapResponse = from result in xml.Descendants(XName.Get("LoginResult", xmlNamespace))
let cookieNameElement = result.Element(XName.Get("CookieName", xmlNamespace)) where cookieNameElement != null
let timoutSecondsElement = result.Element(XName.Get("TimoutSeconds", xmlNamespace)) where timoutSecondsElement != null
let errorCodeElement = result.Element(XName.Get("ErrorCode", xmlNamespace)) where errorCodeElement != null
select new SoapResponse
{
CookieName = cookieNameElement.Value,
TimeoutSeconds = Convert.ToInt32(timoutSecondsElement.Value),
ErrorCode = errorCodeElement.Value
};
I는이 Using LINQ to XML to Parse a SOAP message 게시물에 매우 유사한 포스트 것을 알고,하지만 난 주위를 작동 할 수있는 방법을 찾을 수 없습니다.
미리 감사드립니다. :)