1
SOAPメッセージを特定のクラスに解析しようとしていますが、問題があります。SOAPを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
};
を私がこのUsing LINQ to XML to Parse a SOAP messageポストに非常によく似ポストであることを知っているが、私はそれを回避する方法を見つけることができません。
ありがとうございます! :)