在尝试反序列化SOAP响应时遇到错误。我无法以字符串的形式获取响应,但是我还是从
处获取了该字符串并从xml中生成了c#类。using (var httpClient = new HttpClient(handler))
{
var httpContent = new StringContent(xmlString, Encoding.UTF8, "text/xml");
httpContent.Headers.Add("SOAPAction", Common.EPhytoNamespace);
HttpResponseMessage message = httpClient.PostAsync(_settings.HubServiceUrl, httpContent).Result;
envelope = message.Content.ReadAsAsync<HubServiceContracts.TrackingInfo.Envelope>().Result;
}
我收到以下异常:
SerializationException:在第1行的位置65处出错。应从名称空间'http://schemas.datacontract.org/2004/07/eCert.Bll.HubServiceContracts.TrackingInfo'获得元素'Envelope'。.遇到名称为'Envelope'的名称为'元素',名称空间为'http://schemas.xmlsoap.org/soap/envelope/'。
这是生成的c#对象的结构:
[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Body
{
[XmlElement(ElementName = "GetEnvelopeTrackingInfoResponse", Namespace = "http://ephyto.ippc.int/")]
public GetEnvelopeTrackingInfoResponse GetEnvelopeTrackingInfoResponse { get; set; }
}
[Serializable]
[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "S", Namespace = "http://www.w3.org/2000/xmlns/")]
public string S { get; set; }
}
请帮助我做错事情。