On Mon, Jul 24, 2006 at 12:26:45PM +0100, Andrew Knott
wrote:> As a part of my current project I need to hook up to a particular
> XMLRPC webservice that won''t be available for me to use until
close
> to launch date...
Can I just say: mock objects. Soooooo much less effort to setup and use. I
use Test::Unit::MockObject, and it works *really* well. You''ve got as
much
chance of making that work right than rewriting the webservice, anyway.
Onto the question at hand, though...
> So I am trying to recreate the webservice that
> mirrors the live one so I can test my application correctly. So I
> have the live web service API documentation and I am trying to
> reverse engineer a web service out of it...
The API documentation is a set of XML call/response document pairs? Ouch.
> << Returning
>
> <?xml version="1.0" encoding="UTF-8"?>
> <methodResponse>
> <params>
> <param>
> <value>
> <struct>
> <member>
> <name>success</name>
> <value>
> <boolean>1</boolean>
> </value>
> </member>
> <member>
> <name>responseData</name>
> <value>
> <struct>
> <member>
> <name>type</name>
> <value>
> <string>C</string>
> </value>
> </member>
> </struct>
> </value>
> </member>
> </struct>
> </value>
> </param>
> </params>
> </methodResponse>
Turning this into something a little more readable, I get:
{:success => 1, :responseData => {:type => ''C''}}
Does that seem to match up to you?
> Now, by the looks of things I need to do something like.
>
> class IsCorrectApi < ActionWebService::API::Base
> api_method :isValid,
> :expects =>[MyCall,{:code=>:string}],
> :returns =>[Success,MyResult]
> end
That :returns is wrong, if I got my translation correct. I''d go with
:returns => ResponseSet, and then define:
class ResponseData < AWS::Struct
member :type, :string
end
class ResponseSet < AWS::Struct
member :success, :boolean
member :responseData, ResponseData
end
But that''s a totally bong response structure -- why not just flatten it
back
to {:success => :boolean, :type => :string}? I''m guessing that
ResponseSet
is a variably composed struct, in which case -- have fun with that one.
You need to dance around the API designer singing the WSDL song, whilst
beating him/her with a cluebat. Whilst SOAP has more warts internally, I
never have to deal with them, and at least it has a programmatic way of
describing how the API works, so you can have software work out this sort of
mess. I''ve read that you can describe XML-RPC with WSDL, but
I''ve never
seen how that might be done in practice.
> But you can see from the returning XML above, that There is a
> responseData struct inside of a struct, so how does this work?
You just put the struct inside the struct, as shown.
> Should I just treat responseData as a string and do some XML
> processing on it?
I wouldn''t recommend it.
On another point entirely, if this really is going to be a throwaway thing,
consider just giving AWS the heave-ho and using the native-Ruby XML-RPC
server to produce your test service -- there''s a lot less overhead
involved.
IMO, the primary reason why AWS and it''s AWS::API::Base stuff is so
handy is
because it''ll write the SOAP WSDL for you automatically, which is
Totally
The Stuff. But since you don''t want any of that, it seems pointless
overhead to be using AWS.
- Matt