从.net访问webservice,抛出错误

时间:2010-01-05 05:33:00

标签: .net web-services

访问cgi Web服务时,会抛出错误[xml文档中存在错误(] 仅当返回参数是对象数组时才会发生此错误

如何解决这个问题?

------------ execption details ---------------  System.InvalidOperationException未处理   Message =“XML文档中存在错误(1,452)。”   来源= “的System.Xml”   堆栈跟踪:        在System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle,XmlDeserializationEvents事件)        在System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle)        在System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage消息,WebResponse响应,流responseStream,布尔asyncCall)        在System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,Object []参数)        at MyWebService.CallMyMethod(String hostName,String YourAppMyApptoken,Int32 subscription_id)在D:\ Samjog \ Temp Project \ ProxyTest \ ProxyTest \ MyWebService.cs:第93行        在D:\ Samjog \ Temp Project \ ProxyTest \ ProxyTest \ Form1.cs中的ProxyTest.Form1.btnListFeeds_Click(Object sender,EventArgs e):第209行        在System.Windows.Forms.Control.OnClick(EventArgs e)        在System.Windows.Forms.Button.OnClick(EventArgs e)        在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)        在System.Windows.Forms.Control.WmMouseUp(消息& m,MouseButtons按钮,Int32点击)        在System.Windows.Forms.Control.WndProc(消息& m)        在System.Windows.Forms.ButtonBase.WndProc(消息& m)        在System.Windows.Forms.Button.WndProc(消息& m)        在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)        在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)        在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)        在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)        在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 reason,Int32 pvLoopData)        在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)        在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)        在System.Windows.Forms.Application.Run(Form mainForm)        在D:\ Samjog \ Temp Project \ ProxyTest \ ProxyTest \ Program.cs中的ProxyTest.Program.Main():第18行        在System.AppDomain._nExecuteAssembly(Assembly assembly,String [] args)        在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)        在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()        在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)        在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)        在System.Threading.ThreadHelper.ThreadStart()   InnerException:System.InvalidCastException        Message =“无法将System.Int32类型的对象分配给MyAppWSDLSubscribedFeedInfo类型的对象。”        源= “DZ-gayew”        堆栈跟踪:             在Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMyWebService.Read19_CallMyMethodResponse()             在Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer14.Deserialize(XmlSerializationReader reader)             在System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle,XmlDeserializationEvents事件)        InnerException:

3 个答案:

答案 0 :(得分:2)

如果XML确实存在格式错误,我唯一可以建议的是将响应作为XML获取,然后手动解析。可能只是.Net序列化并不完全理解其格式。

答案 1 :(得分:1)

我遇到了同样的问题,在使用带有.NET客户端的Delphi WebService时出现了这个错误。 我必须得到这个回复

  <message name="CreateCustomerResponse">
    <part name="CustomerCode" type="ns1:TFHOCustomerCode" />
    <part name="return" type="xs:int" />
  </message>

.NET在反序列化该自定义数据类型时出现问题。 改为

  <message name="CreateCustomerResponse">
    <part name="CustomerCode" type="xsd:string" />
    <part name="return" type="xs:int" />
  </message>

完成了工作并最终解决了问题。 希望这对任何人都有帮助,我肯定会在整整一周内找不到这个问题。

此致 索林

答案 2 :(得分:0)

从以下链接获得解决方案 不知道是否有更好的解决方案 http://www.eggheadcafe.com/software/aspnet/34950281/soap-serialization-proble.aspx