That’ about how to use the “ScriptManager” server control to invoke a web service methods i.e. namespace followed by class name followed by the method name. One thing to note is that “ScriptManager” control can only be used to call web services in the same domain. Now lets see how to pass parameters to web methods.
Passing parameters to web method
We will use the following web method to see how we can pass parameters by using “ScriptManager”.
- get_exceptionType method or _exceptionType field/property can be used to get the type of exception raised by the server like “System.Exception”.
- get_message method or _message field/property can be used to get the error message returned by the server.
- _stackTrace field/property or get_stackTrace method can be used to get the stack trace of the error from the server.
- get_statusCode method or _statusCode field/property can be used to retrieve the HTML status code returned from the server.
Passing complex objects
Let see the code of the web method which accepts a complex object and processes it.
The above web method doesn’t have rocket science in it, it just takes a complex object of type “Car” and concatenates the properties and returns it as a string. Now lets the “Car” class. Its same as that we have used in our previous examples.
Below is the JSON way of creating the complex Car object.
In the above code we are trying to create a “ScriptManagerService.Car” object. This is possible because the ScriptManager generates the Proxy classes automatically for us. Now lets see handling a complex type returned from the server. It also is quite simple.
Handling a complex object returned by the server
Lets see the web service which returns the complex object.
Calling methods in a page
Try to know more