views:

60

answers:

1

I'm using ASP.Net AJAX and I created a web service in my application. The service has one method (AddWatchedFolder) and it takes a Name.Space.WatchedFolder as the only parameter. The problem is, ASP.Net AJAX isn't generating a javascript type for Name.Space.WatchedFolder even though I've added the service to a ScriptManager.

I am able to change the parameter type to a string and it works just fine, but I can't use that business object as a parameter because I can't create it from javascript.

The class (Name.Space.WatchedFolder) exists in a separate class library project if that makes any difference.

Any ideas how to get this to work?

A: 

This is how ASP.NET Ajax works. You can try passing your object as anonymous javascript object. The JavaScript serializer will most probably manage to parse your custom object out of the supplied JSON. Here is some code:

ASMX:

[WebMethod]
public void MyMethod(MyObject arg)
{
   return arg.Property1 + arg.Property2;
}

JavaScript:

var arg = { Property1 : "One", Property2 : "Two" };
MyNameSpace.MyService.MyMethod(arg);
korchev
Why does it work that way? Is it because the class is in another project? It creates Javascript types for stuff that is in the same project.
Max Schmeling
It should create a class only for the web service. Does it create classes for the parameters defined in the same project?
korchev
Yes. It has always created types for the parameters, but this time it didn't which I assume is because they're defined in another project.
Max Schmeling