我正在反序列化一个来自我们客户之一的 Web 服务的 XML 文件。
问题是,在使用 xsd.exe 创建类后,我反序列化该文件并得到通常的“XML 文档中存在错误 (2, 2)”。视觉工作室错误。我认为这是第 2 行,它指向命名空间声明:
XML 文件顶部:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<soapenv:Body><MXWorkorderOutResp language="EN" xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header event="0" operation="Response" rsCount="8" rsStart="0" rsTotal="8">
<SenderID build="127" dbbuild="V600-467" majorversion="6" minorversion="1" type="MAXIMO">MX</SenderID>
<CreationDateTime>2009-05-11T09:48:51+01:00</CreationDateTime>
<RecipientID>SUPPLIER</RecipientID>
<MessageID>12420317323327108</MessageID>
</Header>
<Content>
<MXWORKORDER>
<WORKORDER>
一流:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.mro.com/mx/integration")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.mro.com/mx/integration", IsNullable=false)]
public partial class MXWorkorderOutResp {
private MXWorkorderOutRespHeader[] headerField;
private MXWorkorderOutRespContentMXWORKORDERWORKORDER[][][] contentField;
private string languageField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Header")]
public MXWorkorderOutRespHeader[] Header {
get {
return this.headerField;
}
set {
this.headerField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("MXWORKORDER", typeof(MXWorkorderOutRespContentMXWORKORDERWORKORDER[]), IsNullable=false)]
[System.Xml.Serialization.XmlArrayItemAttribute("WORKORDER", typeof(MXWorkorderOutRespContentMXWORKORDERWORKORDER), IsNullable=false, NestingLevel=1)]
public MXWorkorderOutRespContentMXWORKORDERWORKORDER[][][] Content {
我认为有一个错误:
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.mro.com/mx/integration")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.mro.com/mx/integration", IsNullable=false)]
XML 的一部分,但我不知道将其更改为什么 - 或者 VS 想要什么。
感谢大家的帮助,我对这一切还很陌生,我的老板一直在催促我让这一切顺利进行:(
EDIT:有一个内在的例外是的!对不起大家!
{"<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'> was not expected."}
那么如何将这个名称空间声明添加到类中呢?