, пожалуйста, посоветуйте, как сопоставить ответ с классом, потому что из каждого примера, с которым я сталкивался, тело всегда не имеет символа, такого как core:transactionResponse
мой код:
string fileName = @"C:\Users\Lenovo\Downloads\GLResponseXml.xml";
XDocument xDoc = XDocument.Load(fileName);
var unwrappedResponse = xDoc.Descendants((XNamespace)"http://schemas.xmlsoap.org/soap/envelope/" + "Body")
.First()
.FirstNode;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(TransactionResponse));
TransactionResponse response = (TransactionResponse)xmlSerializer.Deserialize(xDoc.Descendants((XNamespace)"http://schemas.xmlsoap.org/soap/envelope/" + "Body")
.First()
.FirstNode
.CreateReader()
);
для десерализируя это soap xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dpss0="bons">
<soapenv:Header/>
<soapenv:Body>
<core:transactionResponse xmlns:bo="http://service.example.co.id/core/bo" xmlns:core="http://service.example.co.id/core">
<response>
<header>
<coreJournal>149326</coreJournal>
</header>
<content xsi:type="bo:OKMessage">
<message/>
</content>
</response>
</core:transactionResponse>
</soapenv:Body>
</soapenv:Envelope>
, но я получил эту ошибку: InvalidOperationException: <transactionResponse xmlns='http://service.example.co.id/core'> was not expected.
Я отображаю ответ в этот класс:
public class GLXmlResponse
{
[XmlRoot(ElementName = "response")]
public class Response
{
[XmlElement(ElementName = "header")]
public Header Header { get; set; }
[XmlElement(ElementName = "content")]
public Content Content { get; set; }
}
[XmlRoot(ElementName = "header")]
public class Header
{
[XmlElement(ElementName = "coreJournal")]
public string CoreJournal { get; set; }
}
[XmlRoot(ElementName = "content")]
public class Content
{
[XmlElement(ElementName = "message")]
public string Message { get; set; }
[XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Type { get; set; }
}
[XmlRoot(ElementName = "transactionResponse", Namespace = "http://service.example.co.id/core")]
public class TransactionResponse
{
[XmlElement(ElementName = "response")]
public Response Response { get; set; }
[XmlAttribute(AttributeName = "bo", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Bo { get; set; }
[XmlAttribute(AttributeName = "core", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Core { get; set; }
}
[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Body
{
[XmlElement(ElementName = "transactionResponse", Namespace = "http://service.example.co.id/core")]
public TransactionResponse TransactionResponse { get; set; }
}
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Header", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public string Header { get; set; }
[XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "soapenv", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Soapenv { get; set; }
[XmlAttribute(AttributeName = "soapenc", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Soapenc { get; set; }
[XmlAttribute(AttributeName = "xsd", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsd { get; set; }
[XmlAttribute(AttributeName = "xsi", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Xsi { get; set; }
[XmlAttribute(AttributeName = "dpss0", Namespace = "http://www.w3.org/2000/xmlns/")]
public string Dpss0 { get; set; }
}
}
нужна помощь в настройке объекта класса