2010-01-05 157 views
0

當訪問一個CGI Web服務,它引發錯誤[有XML文檔中的錯誤(] 此錯誤只發生如果返回paramater是對象的數組訪問web服務,拋出錯誤

如何解決這個問題?

------------ execption details --------------- System.InvalidOperationException is unhandled Message =「There is在XML文檔(1,452)中出錯。「 Source =」System.Xml「 StackTrace: at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,S tring encodingStyle,XmlDeserializationEvents events) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle) at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message,WebResponse response,Stream responseStream,Boolean asyncCall) at:System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,Object [] parameters) at D:\ Samjog \ Temp Project \ ProxyTest \ ProxyTest \ MyWebService.CallMyMethod(String hostName,String YourAppMyApptoken,Int32 subscription_id) MyWebService.cs:line 93 at D:\ Samjog \ Temp Project \ ProxyTest \ ProxyTest \ Form1.cs中的ProxyTest.Form1.btnListFeeds_Click(對象發件人,EventArgs e):第209行 at System.Windows.Forms.Control.OnClick (EventArgs e) 在Syst em.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message & m,MouseButtons button,Int32 clicks) 在System.Windows.Forms.Control.WndProc(消息&米) 在System.Windows.Forms.ButtonBase.WndProc(消息&米) 在System.Windows.Forms.Button.WndProc(消息&米) 在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息&米) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息&米) 在System.Windows.Forms.NativeWindow.Debug gableCallback(IntPtr的的HWND,MSG的Int32,IntPtr的WPARAM,IntPtr的LPARAM) 在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG & MSG) 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods。 IM3ComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 reason,Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext上下文) at System.Windows.Forms.Application.Run(Form mainForm) at ProxyTest.Program.Main()in D:\ Samjog \ Temp Project \ ProxyTest \ ProxyTest \ Program.cs:line 18 at System。 AppDomain._nExecuteAssembly(大會組件,字串[] args) 在System.AppDomain.ExecuteAssembly(字符串assemblyFile,證據assemblySecurity,字串[] 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 消息=「無法分配類型System.Int32的對象到MyAppWSDLSubscribedFeedInfo類型的對象。「 Source =」dz-gayew「 StackTrace: at Microsoft.Xml.Serialization.GeneratedAssembly。XmlSerializationReaderMyWebService.Read19_CallMyMethodResponse() 在Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer14.Deserialize(XmlSerializationReader閱讀器) 在System.Xml.Serialization.XmlSerializer.Deserialize(的XmlReader XmlReader中,字符串的encodingStyle,XmlDeserializationEvents事件) 的InnerException:

回答

2

如果XML確實格式不正確,我可以建議的唯一方法是以XML形式獲取響應,然後手動解析它。這可能只是.Net序列化不能完全理解它的格式。

+0

你能就如何做到這一點的詳細信息? – Samjog 2010-01-06 06:58:09

1

我有同樣的問題,收到這個錯誤耗費了德爾福的WebService與.NET客戶端。 我一定要得到這個響應

<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> 

做了工作,最後失去了問題。 希望這對任何人都有幫助,我肯定整整一個星期都在爲這個問題進行挖掘。

問候, 索林