[Xml-compile] WSDL::Compile
"Alex J. G. Burzyński"
ajgb at ajgb.net
Wed Nov 25 16:51:11 GMT 2009
Hi Mark,
(resending due to incorrect encoding, sorry)
Mark Overmeer wrote:
> * "Alex J. G. Burzyński" (ajgb at ajgb.net) [091125 14:53]:
>
>> First I'd like to thank for your excellent XML::Compile module!
>>
>> As my thanks I've created a WSDL::Compile::Serialize module that can handle
>> serializing the object data/hashref to and from XML::Compile::SOAP::Client.
>>
>
> It is quite hard to understand the code without examples. Maybe you can
> add your script to an examples directory?
>
>
Example usage of the WSDL::Compile::Serialize
use strict;
use warnings;
use XML::Compile::WSDL11;
use XML::Compile::SOAP11;
use XML::Compile::Transport::SOAPHTTP;
use WSDL::Compile::Serialize;
use Example::Op::CreateCustomer::Request;
use Example::Op::CreateCustomer::Response;
use Example::CT::Contact;
my $s = WSDL::Compile::Serialize->new();
my $request_class = 'Example::Op::CreateCustomer::Request';
my $response_class = 'Example::Op::CreateCustomer::Response';
my $contact_class = 'Example::CT::Contact';
my $req = $request_class->new(
'TemplateCode' => 'example',
'Contact' => $contact_class->new(
'Street' => 'example',
'County' => 'example',
'City' => 'example'
),
'CustomerID' => [ 'example', 'example' ],
'Contacts' => [
$contact_class->new(
'Street' => 'example',
'County' => 'example',
'City' => undef
),
$contact_class->new(
'Street' => 'example',
'County' => 'example',
'City' => 'example'
),
],
'BuildingNumber' => undef,
'CustomerType' => ['example', undef, 'example2'],
);
my $wsdl = XML::Compile::WSDL11->new('example/Example.wsdl');
my $call = $wsdl->compileClient('CreateCustomer');
# turn object into hashref
my $call_request = $s->for_xml( $req );
my $answer = $call->( %$call_request );
# turn hashref into class args
my $res_args = $s->for_class( $response_class, $answer );
my $res = Example::Op::CreateCustomer::Response->new(
%$res_args
);
This allows developers to work with classes instead of building the
hashrefs. Those Request/Response/Fault classes could have their own
methods, triggers, extended validation etc.
> What I see from an initial inspection of your code, is that you created
> XML nodes for the WSDL yourself. However, there is a far simpler
> solution. Something along the lines of:
>
> my $wsdl = XML::Compile::WSDL->new;
> my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
>
> my $def = { # create your WSDL information here
> wsdl_message => ...
> , wsdl_service => ...
> };
>
> my $xml = $wsdl->writer("wsdl:definitions")->($doc, $def);
> $xml->toFile($fn, 1);
>
> That way, you get a WSDL which will strictly follow the WSDL and XML
> encoding rules.
>
Thanks for tip - I'll certainly take a look at that.
Cheers,
Alex
More information about the Xml-compile
mailing list