0

I have a WCF endpoint which is sending an XML result. My Data contract is as per the follows:

    [DataContract(Name = "response")]
    public class GetAppointmentResult : response

However my output is showing the XML as <GetAppointmentResult>.

Is this the wrong way of doing this if the output is XML and therefore using an XML Serializer ?

  • The dataContract name has to match the tag tag name including lowercase and uppercase letters. – jdweng Oct 21 '20 at 16:00
  • Judging from the datacontract you gave, there is no problem. You can provide the piece of code for converting data into xml format so that we can better help you solve the problem. – Ding Peng Oct 22 '20 at 03:11
  • I can't reproduce your problem in a demo fiddle, see https://dotnetfiddle.net/rcHZwS. I think we will need to see a [mcve] to help you. Are you sure you're not actually using `XmlSerializer` instead of `DataContractSerializer`? – dbc Oct 22 '20 at 03:20
  • I am using XmlSerializer as i need data within the result to be a list of variables: ` ` These have XML Attributes to show the data. – Sam Brueton Oct 22 '20 at 10:48
  • If you are using `XmlSerializer` you must use [`[XmlRoot("response")]`](https://learn.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlrootattribute?view=netcore-3.1). See [{" was not expected.} Deserializing Twitter XML](https://stackoverflow.com/a/1557145/3744182), [Parse Soap XML into Object in C#](https://stackoverflow.com/a/32471240/3744182) and [Attributes That Control XML Serialization](https://learn.microsoft.com/en-us/dotnet/standard/serialization/attributes-that-control-xml-serialization). – dbc Oct 22 '20 at 14:57

0 Answers0