序列化消息体时出错

时间:2014-01-24 13:19:06

标签: c#

我在尝试使用服务(第三方)时遇到异常,下面是异常的堆栈跟踪。

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

之前它工作正常,但在更新服务引用后,它开始抛出上述异常。

还尝试了以下链接中描述的解决方案,但没有任何帮助。

There was an error in serializing body of message

感谢您在解决问题方面的帮助。

以下是我正在使用的代码

// reportContent将xml数据作为字符串。

      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)//错误显示在此行中。

1 个答案:

答案 0 :(得分:0)

终于找到了这个问题的解决方案。添加服务引用后,默认情况下,Reference.cs中的payload属性返回一个类型为'Object'的值,我将其更改为返回System.Xml并单击它。