From the languages and programming environments like C, the .NET CLR and Java we are know proxy generation mechanisms based on IDL and RPC for a long time. These generated classes and files enable the programmer to call a server-side method by calling a local method with the same name. The implementation of the network transfer is taken off your application code.
For WebServices there is also a description standard called WSDL http://www.w3.org/TR/wsdl that fully describes a Webservice communication and a WSDL Compiler can generate those proxy classes in Sourcecode or binary format using this information only.
To create such Proxy Objects we only need one line of code as we will see below.
The implementation of the real communication is implemented in the ajax include file in the webservice region. In this script include the variable proxies is created as an empty Objects. All local service objects and all local methods will be attached to this object. Calling a server-side Methods looks like this:
proxies.CalcService.func = displayFactors; // async result proxies.CalcService.CalcPrimeFactors(12); // call
Also a synchronous version can be used. The func attribute must be null and the result of the server-side method is directly returned from the client method.
var factors = proxies.CalcService.CalcPrimeFactors(12);
Using this approach proxies ist the only one global variable that we need. Conflicts with other variables are minimized.
All the information that is needed to make the SOAP call is attached to every method object and another object is used to hold the information about the webservice.
|proxies.service.url||URL of the WebService|
|proxies.service.ns||Namespace of the WebServices|
|proxies.service.function()||Calling a server-side method|
|proxies.service.function.fname||Name of the method|
|proxies.service.function.action||soapaction of the method|
|proxies.service.function.params||Array with the names of the parameters|
|proxies.service.function.func||Function receiving the result|
|proxies.service.function.onException||Function to handle an exception|
|proxies.service.function.corefunc||Debugging helper function|
|proxies.service.function.service||Link back to the service object|
If you only have to realize a small application you can easily create this code manually by reading all the information you need from the webservice description. Retrieving such a description is very easy when implementing in ASP.NET. You navigate to the URL of the webservice and use the Link that is available on this page. You can also attach a WSDL Parameter:
You do not have to write the script fort he proxy yourself as you can see and you only need one html tag.
The files for the implementation are available on the sample webside (see sidebar).