XMLDeserialize: Error in XML document (1,2)

Generated service contract and data contracts from a WSDL using svcutil. Next, I tried to deserialize a XML message into the generated object. I received the following error: There is an error in XML document (1,2). After debugging code, I found out the [XmlRoot] attribute was not generated. Below, you see the generated datacontract with the XmlRootAttribute manually added:

[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”, “4.6.1087.0”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“code”)]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = “http://dsplatform.nl/participant/TechnischGereed”)]
[System.Xml.Serialization.XmlRootAttribute(“TechnischGereedbericht”, Namespace = “http://dsplatform.nl/participant/TechnischGereed”, IsNullable = false)]
public partial class TechnischGereedberichtXOPType : BerichtTypeXOP

And then, as an example, the code to deserialize the xml message:

public HttpResponseMessage PostTG([FromBody]string document, string integrationId, string formCode)
{

TechnischGereedberichtXOPType TGbericht;

XmlSerializer serializer = new XmlSerializer(typeof(TechnischGereedberichtXOPType));
using (XmlReader reader = XmlReader.Create(new StringReader(document)))
{
TGbericht = (TechnischGereedberichtXOPType)serializer.Deserialize(reader);
}

Leave a Reply

Your email address will not be published. Required fields are marked *