access webservice from .net ,throws error
When accessing a cgi web service ,it throws the error [there is an error in xml document(] this error happens only If the return paramater is an array of objects
how to resolve this?
------------execption details--------------- System.InvalidOperationException was unhandled Message="There is an error in XML document (1, 452)." 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.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 MyWebService.CallMyMethod(String hostName, String YourAppMyApptoken, Int32 subscription_id) in D:\Samjog\Temp Project\ProxyTest\ProxyTest\MyWebService.cs:line 93 at ProxyTest.Form1.btnListFeeds_Click(Object sender, EventArgs e) in D:\Samjog\Temp Project\ProxyTest\ProxyTest\Form1.cs:line 209 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.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) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at开发者_JAVA技巧 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.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 context) 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(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.InvalidCastException Message="Cannot assign object of type System.Int32 to an object of type MyAppWSDLSubscribedFeedInfo." Source="dz-gayew" StackTrace: at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMyWebService.Read19_CallMyMethodResponse() at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer14.Deserialize(XmlSerializationReader reader) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) InnerException:
If the XML is really malformed, the only thing I can suggest is getting the response as XML and then parsing it manually. It may just be that the .Net serialization does not fully understand its format.
I had the same problem, getting that error consuming a Delphi WebService with a .NET client. I have to get this response
<message name="CreateCustomerResponse">
<part name="CustomerCode" type="ns1:TFHOCustomerCode" />
<part name="return" type="xs:int" />
</message>
.NET have a problem deserializing that custom data type. Changing to
<message name="CreateCustomerResponse">
<part name="CustomerCode" type="xsd:string" />
<part name="return" type="xs:int" />
</message>
did the work and finally lost the problem. Hope this will be helpful for anyone, i sure lost one whole week diging for this problem.
Regards, Sorin
Got the solution from following Link dont know if there is any better solution http://www.eggheadcafe.com/software/aspnet/34950281/soap-serialization-proble.aspx
精彩评论