segunda-feira, 10 de setembro de 2007

Web Services with Caché/Ensemble - The Quest - chpt 3

And this is the end of trilogy...

As I said at the end of last post, the chapter 2, when I was writing the SOAP-Body manually, the requisition message was correctly understood by the Web Service. However, for some unknown reasons, the response message was not returning correctly to my code in Caché Object Script. At first, I thought it wasn't working at all, but after I analyzed the TCP stream with a sniffer, I realized that the Web Service was returning correclty. The problem was with Caché/Ensemble, who didn't understand the answer message.

Wondering if the problem wasn't with my modifications, I tested all the WS Client classes without any modifications, but the error was the same. Conclusion: all work so far was for nothing. So, after analyzing Caché's source, and through some little clues the error on screen, I realized that Caché was giving error because it tried to instantiate a class based in WS answer message, but it failed:


(an example of a response message, informing the request was correctly processed)

By then, tired of navigating through source code and bad written documentation, I decided to went down: since I the Caché's %SOAP package could not work fine with the given Web Service, I was going down in the protocol stack, to make it work. Caché doesn't have 'native' classes to deal straight with HTTP (at least, I didn't find any), but Ensemble has an HTTP "Adapter".

(One parenthesis: Adapters in Ensemble are pieces of software which have the function of connecting Ensemble with other systems/technologies. The documentation on this Adapters is really bad, as an example, in this page listing the Adapters, the HTTP is not even listed, and a lot of Adapters there, simply doesn't exist here, in my installation. Freaking...)

After a little testing, I discovered that I was not able to use HTTP Adapter with the Web Service, because this Adapter doesn't let me set a header SOAPAction, in HTTP headers, which is mandatory for this Web Service to work.

As I couldn't use HTTP classes, I went one step below in protocol stack, and use TCP. Ensemble's TCP Adapter is nothing more than a wrapper for Caché's Socket classes, something I already talked about in two previous posts, here (about client sockets) and here (about server sockets).


(protocol stack - almost at IP level =P )

The good thing in using TCP is that you have control over everything, of the HTTP headers, the SOAP XML message, etc... The bad thing is that in order to use it, besides you must understand a great part of all this stuff, you have to write all manually. But as the Caché/Ensemble tools availables were just giving me headache (and errors), I had not much choice. XD

Take a look how it ended (more or less, here I simplified some stuff):



Finally, with a horrible code and using some anti-patterns, all worked. And all that with Ensemble, which, here, some call "Integrator"... I wonder if it wasn't...

0 comentários: