What’s my Problem
Object returned from the ASMX service is used in Silverlight application. Class has methods but the result from the ASMX WebMethod does not show methods on the object.
Tell me more
here is my class
public class Dog
{
public string Name{get;set;}
public void Bark();
}
here is the WebMethod
[WebMethod]
public List<Dog> Findlabrador()
{
blah blah blah
return list_of_labrador;
}
the silverlight code
void LabradorFetchCompleted(object sender, LabradorFetchCompletedEventArgs e)
{
var list_of_labrador = e.Result;
foreach(var labradorDog in list_of_labrador)
{
labradorDog.Bark();
//** WTH my labrador can't BARK** Bark method is not shown in intellisense there is compilation error if i explicitly specify
}
}
I am a programmer not a layman
Ok hmm, let me put in your words. Here are steps for you to reproduce the issue
-
Create a Silverlight Application project ( Let VS create Website to host the application)
-
Create a Silverlight Class library create the Dog class inside it
-
Compile the Silverlight Class library to assembly(
Dog.dll) -
Add reference to
Dog.dllsilverlight assembly to the silverlight application project -
Add a WebService application to the project ( DogService.asmx note the
asmxextension) -
Add a reference to the Silverlight
Dog.dllassembly for theDogService -
return
hardcoded List<Dog>class from a WebMethod inside it -
Add a reference from the Service to Silverlight application, create a instance of proxy client and invoke the method
-
Watch as your Dog too can’t Bark 🙁
Methods are never serialized. Only data. Your methods, events, indexers, constructors, etc, will never be serialized.
You should not be using ASMX services anyway. Use WCF instead. WCF, among other things, gives you the ability to share datatypes between the client and service. This would allow something like “serializing methods”: the same methods could be used both on the client and server.