![]() |
|
[ASP.NET] WebMethod Call From Client Fails With System.InvalidOperationException |
bamccaig
Member #7,536
July 2006
![]() |
Essentially, I have a WebMethod defined in C#/.NET and I'm trying to call it on the client in JavaScript: ClassName.MethodName(arg1, arg2, ... argN, succeeded_handler, failed_handler); That fails, however, seemingly during deserialization. It sounds like it's failing to deserialize a dictionary (i.e., IDictionary), but not only does the JavaScript proxy object have nothing remotely related to a collection or container, but as far as I can tell neither does the C# class (neither of which I can show for NDA reasons). The exception sent back to the client seems to all be .NET related though, so I can show that:
at System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject( IDictionary`2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal( Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain( Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject) at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType( Object o, Type type, JavaScriptSerializer serializer) at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal( Int32 depth) at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary( Int32 depth) at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal( Int32 depth) at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize( String input, Int32 depthLimit, JavaScriptSerializer serializer) at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize( JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T]( String input) at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest( HttpContext context, JavaScriptSerializer serializer) at System.Web.Script.Services.RestHandler.GetRawParams( WebServiceMethodData methodData, HttpContext context) at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall( HttpContext context, WebServiceMethodData methodData)
The JavaScript proxy object is created using the automatically generated "constructor" function: var o = new SomeNamespace.SomeClass(); o.Property = 28; When passed into the proxy Web service method, it becomes a JSON string like this: {__type:"SomeNamespace.SomeClass", Property:28} There are obviously no dictionaries or even arrays in that... I just triple-checked the C# class and confirmed that there are definitely no public dictionary-like members (I'm fairly confident there are no private or protected ones either, but even so I think the serialization only deals with public members). Anybody know what might be wrong? We aren't at all new to using ASP.NET with the SOAP/AJAX interface. We've been doing it now for months and everything else is still working... The method failing to be called isn't new either. It's been in use for a few months itself and to my knowledge still works in code that has been using it for the past few months... The declaration is something like... [WebMethod(EnableSession = true)] public string MethodName(object ParameterName) None of the error handlers on the server are called. All WebMethods, including this one, are wrapped in a delegate and executed through a centralized static method so that we can log exceptions, etc. That isn't happening either, so it's gotta be before it gets there. None of the breakpoints I've set have been hit so I don't think it's getting into our code. The exception is caught and serialized into a SOAP message by the server (which is where the above exception information comes from... I pulled it from the JavaScript debugger). It would be nice if I could set a breakpoint in the server code where the SOAP is handled and see specifically what is going on when the exception is thrown... HALP!!1 ** EDIT ** I don't know why it fails, but the part that was failing was essentially an interface layer between old and new APIs. I found a more direct way to the new API that doesn't fail...for unknown reasons. In any case, it's working... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
|