vote up 0 vote down
star

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?

flag
add comment

1 Answer:

vote up 0 vote down

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);
link|flag
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 Apr 25 at 15:14
It should create a class only for the web service. Does it create classes for the parameters defined in the same project? – korchev Apr 25 at 18:18
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 Apr 30 at 18:50
add comment

Your Answer:

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.