xml序列化错误
本文关键字:错误 序列化 xml | 更新日期: 2023-09-27 18:00:35
我正在尝试使用xml序列化来序列化对象(MCCI_IN000001TR01Message,它是一个要使用web服务的类),但是在序列化它时我遇到了一个错误
MCCI_IN000001TR01Message message = new MCCI_IN000001TR01Message()
{
id = new MCCI_IN000001TR01MessageID()
{
root = "2.16.840.1.113883.3.129.2.1.2",
extension = _sGuid
},
acceptAckCode =
new MCCI_IN000001TR01MessageAcceptAckCode()
{
code = "AL"
},
receiver =
f_Receiver(),
sender = f_Sender(),
controlActEvent = f_ControlActEvent(dialysis)
};
MCCI_IN000002TR01Message donen = service.MCCI_AR000001TR_MCCI_IN000001TR(message);
MCCI_IN000001TR01Message
是一个不是我创建的类,它是web服务类。
在此上下文中不能使用System.String类型。描述:在执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误以及错误在代码中的来源的更多信息。
Exception Details: System.InvalidOperationException: **The type System.String may not be used in this context.**
[InvalidOperationException: The type System.String may not be used in this context.]
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write216_StrucDocText(String n, String ns, StrucDocText o, Boolean isNullable, Boolean needType) +1823
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write403_Item(String n, String ns, POCD_MT000027TR01SocialSecurityFollowNumberSection o, Boolean isNullable, Boolean needType) +1087
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write404_POCD_MT000027TR01Component45(String n, String ns, POCD_MT000027TR01Component45 o, Boolean isNullable, Boolean needType) +942
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write434_Item(String n, String ns, POCD_MT000027TR01ReceptionDataset o, Boolean isNullable, Boolean needType) +1192
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write435_POCD_MT000027TR01Component44(String n, String ns, POCD_MT000027TR01Component44 o, Boolean isNullable, Boolean needType) +942
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write436_Item(String n, String ns, POCD_MT000027TR01StructuredBody o, Boolean isNullable, Boolean needType) +1477
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write437_POCD_MT000027TR01Component1(String n, String ns, POCD_MT000027TR01Component1 o, Boolean isNullable, Boolean needType) +942
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write438_POCD_MT000027TR01Dialysis(String n, String ns, POCD_MT000027TR01Dialysis o, Boolean isNullable, Boolean needType) +1951
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write439_MCCI_IN000001TR01Subject(String n, String ns, MCCI_IN000001TR01Subject o, Boolean isNullable, Boolean needType) +781
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write440_Item(String n, String ns, MCCI_IN000001TR01ControlActEvent o, Boolean isNullable, Boolean needType) +878
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write441_MCCI_IN000001TR01Message(String n, String ns, MCCI_IN000001TR01Message o, Boolean isNullable, Boolean needType) +1627
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterMCCI_IN000001TR01Message.Write442_MCCI_IN000001TR01(Object o) +144
[InvalidOperationException: There was an error generating the XML document.]
waSaglikNetUygulamasi._Default.Page_Load(Object sender, EventArgs e) in C:'Users'duygu.akmaz'Desktop'FMC-Projeler'SaglikNet'trunk'Default.aspx.cs:255
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
public string ToXml(DataSet ds)
{
using (var memoryStream = new MemoryStream())
{
using(TextWriter streamWriter = new StreamWriter(memoryStream))
{
var xmlSerializer = new XmlSerializer(typeof(DataSet));
xmlSerializer.Serialize(streamWriter, ds);
return Encoding.UTF8.GetString(memoryStream.ToArray());
}
}
}