Sunday, March 11, 2012

Web Services Wrapper

It could be exposed via a js variable eg: http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/a916eb4c7f2390db
Interesting idea.Yes [Y] Actually, this is something we've been working on for a while with standard AJAX where I work. I've written a wsdl interegator class that reads the wsdl of a given .net web service and exposes it as a simplified object model. This dll is used by a Code Smith Template to generate javascript objects with the ability to serialize their data for consumption by the web service. There is also another layer that provides gerenic soap interaction and provides a set of javascript methods that can pass the serializable js objects to/from the webservice. What this means to the developer is that we can make ALL of our object interface changes in an XSD file, then autogen the WSDL proxy and the Javascript objects. The only actual code that needs to be written (by hand) are the Web service methods and on the client-side you need a bit of code to utilize the javascript wrapper objects to render the UI elements (and/or populate existing Html elements with data). An example of the code required to request some data from a web service on the client is...
var request = new GetApplicantInfoRequest();
request.ApplicantId = document.getElementById("ApplicantId").value;
var response = GetApplicantInfo(request); // This line calls the web service and returns the results
ShowResponse(response); // Generalized display routine

In this example GetApplicantInfoRequest, GetApplicantInfo, and the objects they return were all auto generated by the scripts based on inforamation gleaned from the web service's WSDL. The developer never even has to see the code it generates to be able to use it. (They just have to be aware of the contract specified by the WSDL interface.
Now comes Atlas and our first idea is to try to get them working together (or completely replace our own code with stuff from the Atlas library) but alas, the Atlas objects don't use SOAP (they use JSON instead), so we are currently researching ways to leverage what's provided in the best way possible.
Please keep this site posted of any headway you make in this area as this is a very active topic for us right now too.
This is *exactly* what I need. Will the web services wrapper be available anywhere?

Generic web service wrapping can be done via dynamic proxy generation as it has been done many times in the past. I have been playing with my own flavour of this, which can be found here: http://www.mscorlib.com/ajaxws/DynWs.aspx Consider it pre-alpha and not all listed services actually work, doesnt use JSON to serialize but that could be added later including the dynamic JSON proxy generation for the final client. I wanted to see what would be involved in actually getting something like this working.
The original conversation regarding wrapping services can be found here: http://forums.asp.net/ShowPost.aspx?PageIndex=1&PostID=1050756#1050756
My method above uses an early version ofhttp://ajaxpro.schwarz-interactive.de/ and some code which I had lying around which does the dynamic proxy generation of the actual WSDL endpoint.
The source will never be posted, I wanted to simply show that I can be done, and offer any help to others that want any insight as to how I did it.

I wrote a library to use "AJAX" (sync or async) to consume Web Services. You can find the article, the source code (less than 8 KB) and some demos at http://www.guru4.net/articoli/javascript-soap-client/en/
Your comments are welcome!

No comments:

Post a Comment