1

I have to use XMLSerializer to serialize an object as a soap encoded xml.

I've found the following article : https://learn.microsoft.com/en-us/dotnet/standard/serialization/how-to-serialize-an-object-as-a-soap-encoded-xml-stream

But an error occurs once i call the serialize method...

The error message is:

Token StartElement in state Epilog would result in an invalid XML document.

Do you have any idea how i can fix it ?

    XmlTypeMapping myTypeMapping = new 
    SoapReflectionImporter().ImportTypeMapping(typeof(typeOfMyObject));

    XmlSerializer ser = new XmlSerializer(myTypeMapping);

    MemoryStream Stream = new MemoryStream;
    ser.Serialize(Stream,myObject);
jazb
  • 5,498
  • 6
  • 37
  • 44
tibz64
  • 45
  • 8
  • may we have your input data ? could you post myTypeMapping class – Z.R.T. Oct 30 '18 at 01:50
  • typeOfMyObject is a WSDL file I have added through "add service reference". – tibz64 Oct 30 '18 at 10:46
  • possible duplicate question https://stackoverflow.com/questions/3288606/writing-xml-in-c-sharp-token-startelement-in-state-epilog-would-result-in-an) – Z.R.T. Oct 30 '18 at 11:24
  • Can't reproduce, see https://dotnetfiddle.net/Vj6yc6. Can you please [edit] your question to provide a [mcve]? We would need to see a definition for the type `typeOfMyObject`, plus code showing how an instance is constructed that generates the error when serialized. Or if you point us to the WSDL, that might be enough. – dbc Oct 30 '18 at 16:49
  • Related or duplicate: [Extension method to serialize generic objects as a SOAP formatted stream](https://stackoverflow.com/q/6401075/3744182). See also [C# Serialize object to SOAP string array issue](https://stackoverflow.com/q/52893279/3744182) which has a [mcve]. – dbc Oct 30 '18 at 23:29

0 Answers0