Syed
Syed

Reputation: 53

There was an error in serializing body of message

I am getting exception on trying to consume a service (3rd party), below is the stack trace for the exception.

StackTrace  "   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)\r\n   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)\r\n   at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object returnValue, Object[] parameters)\r\n   at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)" string

Earlier it was working fine, but after updating the service reference it started throwing the above exception.

Also tried the solution described in the below link, but was of no help.

There was an error in serializing body of message

Appreciate your kind help in resolving the same.

Below is the code that i am using

//reportContent is having xml data as string.

      XmlDocument xmlReportDocument = new XmlDocument();

        xmlReportDocument.LoadXml(reportContent);



           RequestHandlerProcessSoapClient ws = new RequestHandlerProcessSoapClient();

            ws.ClientCredentials.UserName.UserName = _reportFormatData.User;

            ws.ClientCredentials.UserName.Password = _reportFormatData.Password;

 ///Create the request

                myRequest request = new myRequest();

                request.Requestor = new Requestor();

                request.Requestor.ApplicationID = _reportFormatData.ApplicationId;

                request.Requestor.Stylesheet = template;

                request.Requestor.Environment = _reportFormatData.Environment;

                request.Payload = xmlReportDocument;

                ///Setup the attachements

                myAttachmentRequest attachmentrequest = new myAttachmentRequest();

                attachmentrequest.setRequest = request;

myResponse serResp = ws.renderDocument(attachmentrequest)//Error shows up in this line.

Upvotes: 1

Views: 3957

Answers (1)

Syed
Syed

Reputation: 53

Finally found the solution to this question. After adding a service reference, by default payload property in Reference.cs was returning a value of type 'Object', and this i changed it to return System.Xml and it clicked.

Upvotes: 1

Related Questions