【问题标题】:Web Service error "Error in deserializing body of reply message for operation"Web 服务错误“反序列化操作回复消息正文时出错”
【发布时间】:2015-05-11 20:29:35
【问题描述】:

尝试调用 HP Operations Orchestration 的 Web 服务时出现以下错误。似乎 WSDL 没有正确格式化响应,或者我没有正确处理响应。我在网上看到的大多数事情都是指消息大小太小。情况似乎并非如此。我已更改为仅使用 var 但这无济于事。有什么想法吗?

电话:var h = OOSRClient.getFlowRunHistoryByRunId(1);

例外:

System.ServiceModel.CommunicationException was caught
  HResult=-2146233087
  Message=Error in deserializing body of reply message for operation 'getFlowRunHistoryByRunId'.
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
       at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at TestOO.OOSR.WSCentralService.getFlowRunHistoryByRunId(getFlowRunHistoryByRunIdRequest request)
       at TestOO.OOSR.WSCentralServiceClient.TestOO.OOSR.WSCentralService.getFlowRunHistoryByRunId(getFlowRunHistoryByRunIdRequest request) in c:\Users\slippi3\Documents\Visual Studio 2013\Projects\TestOO\TestOO\Service References\OOSR\Reference.cs:line 7526
       at TestOO.OOSR.WSCentralServiceClient.getFlowRunHistoryByRunId(Int64 runId) in c:\Users\slippi3\Documents\Visual Studio 2013\Projects\TestOO\TestOO\Service References\OOSR\Reference.cs:line 7532
       at TestOO.Controllers.HomeController.Index() in c:\Users\slippi3\Documents\Visual Studio 2013\Projects\TestOO\TestOO\Controllers\HomeController.cs:line 118
  InnerException: System.InvalidOperationException
       HResult=-2146233079
       Message=There is an error in XML document (1, 1287).
       Source=System.Xml
       StackTrace:
            at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
            at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
            at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
       InnerException: System.InvalidCastException
            HResult=-2147467262
            Message=Cannot assign object of type System.Object[] to an object of type TestOO.OOSR.WSRunHistoryDetailsExtend[].
            Source=ma3ir41a
            StackTrace:
                 at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderWSCentralService.Read90_Item()
                 at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer45.Deserialize(XmlSerializationReader reader)
                 at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
            InnerException: 

回复如下:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <ns1:getFlowRunHistoryByRunIdResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://wscentralservice.services.dharma.iconclude.com">

<getFlowRunHistoryByRunIdReturn soapenc:arrayType="xsd:anyType[1]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<getFlowRunHistoryByRunIdReturn xsi:type="ns2:WSRunHistoryDetailsExtend" xmlns:ns2="http://iconclude.com/webservices/rss/v2.0/soap">
<uuid xsi:type="xsd:string">1111ac59-6bbe-47fa-841f-94e56c1b2111</uuid>
<flowRevision xsi:type="xsd:string">4</flowRevision>
<runHistoryId xsi:type="xsd:long">1</runHistoryId>
<runName xsi:type="xsd:string"></runName>
<userId xsi:type="xsd:string">AA\AAAAAAA</userId>
<status xsi:type="xsd:string">Resolved</status>
<startTime xsi:type="xsd:long">1302621361380</startTime>
<duration xsi:type="xsd:long">100</duration>
<numSteps xsi:type="xsd:int">5</numSteps>
<scheduledBy xsi:type="xsd:string" xsi:nil="true"/>
</getFlowRunHistoryByRunIdReturn>
</getFlowRunHistoryByRunIdReturn>
</ns1:getFlowRunHistoryByRunIdResponse>
</soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

  • 仅供参考,WSDL 只是一个文档。它不格式化响应。我还建议(仅出于故障排除目的)您只需捕获异常并显示ex.ToString()。这样,您将获得异常想要告诉您的所有信息。
  • 感谢您的回复,我最终发现 WSDL 试图返回的对象和它返回的对象是不同的。最终编写了我自己的类来处理所有事情,到目前为止一切都很好。

标签: c# web-services wcf


【解决方案1】:

WSDL 类生成的问题以及预期的问题。构建我自己的类处理了它。

【讨论】:

  • 为您的答案添加一些细节。显示您创建的类以及它与自动生成的类有何不同。您还应该展示 WSDL 的相关部分以及您可能对为什么会发生这种情况的任何推测。您可以对此答案进行投票。
猜你喜欢
  • 1970-01-01
  • 2019-09-09
  • 1970-01-01
  • 1970-01-01
  • 2021-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多