I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-04-06 16:41:19-07 by tubby
Problem with using more than one XML Namespace
Hi all,
I am integrating with a document/literal wrapped service using SOAP::WSDL. Most things are going fine :)
I have a problem calling a method on the service that uses a mix of the elments from one namespace with a few from a common schema.
i.e.Here's a SOAP UI version of a request that works correctly
<?xml version='1.0' encoding='UTF-8'?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:char="http://www.mycomany.com/schema/charging" xmlns:com ="http://www.mycompany.com/schema/common"> <soapenv:Body> <char:DirectCharge> <char:ProductCode>prod1</char:ProductCode> <char:ProductDescription>someDescription</char:ProductDescription> <char:Classification> <com:Category>BUSINESS_SERVICES</com:Category> </char:Classification> </char:DirectCharge> </soapenv:Body> </soapenv:Envelope>

As you can see the Classification element is in the 'char' namespace, while the Category element is in a 'com' namespace.

wsdl2perl seems to understand it all in as much as the perldoc mentions which namespace each element is in. However, running a test client results in the following XML
<?xml version='1.0' encoding='utf-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <DirectCharge xmlns="http://www.mycompany.com/schema/charging"> <ProductCode>prod1</ProductCode> <ProductDescription>someDescription</ProductDescription> <Classification> <Category xmlns="">BUSINESS_SERVICES</Category> </Classification> </DirectCharge> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Here you can see that the namespace for the Category is blank, whereas it should be 'http://www.mycompany.com/schemas/common' I have a workaround my implmenting my own serializer and doing a regex replace on xmlns="" with the correct one, but now I feel dirty...

Can anyone help? Does SOAP::WSDL support this?
regards
tubby
Direct Responses: 10445 | Write a response
Posted on 2009-04-07 20:14:16-07 by mkutter in response to 10435
Re: Problem with using more than one XML Namespace
Hi,
which version are you using?
Are you using generated classes (which should support this) or are you directly using SOAP::WSDL (by saying
use SOAP::WSDL
?

Martin
Direct Responses: 10448 | Write a response
Posted on 2009-04-08 09:45:04-07 by tubby in response to 10445
Re: Problem with using more than one XML Namespace
Hi Martin,

Thanks for the reply. Using latest version from CPAN as of today.
I'm using generated classes from wsdl2perl and using them like
use MobPayInterfaces::MobpayService::ChargingPortTypeBinding; use MobPayElements::DirectChargeResponse; use MobPayTypes::ClassificationType; use MobPayElements::DirectCharge; # And my serialiser to make it work use MobPaySerialiser; # # Instantiate SOAP endpoint # $interface = MobPayInterfaces::MobpayService::ChargingPortTypeBinding->new(); $interface->set_serializer('MobPaySerialiser'); my $mobpayClassification = MobPayTypes::ClassificationType->new( { # MobPayTypes::ClassificationType Category => $category, # atomic } ); # my $directCharge = MobPayElements::DirectCharge->new(); $directCharge->set_ProductCode($productCode); $directCharge->set_ProductDescription($productDescription); $directCharge->set_Classification($mobpayClassification); my $response = $interface->DirectCharge($directCharge);

The generated classification type is here:

package MobPayTypes::ClassificationType; use strict; use warnings; __PACKAGE__->_set_element_form_qualified(0); our $XML_ATTRIBUTE_CLASS; undef $XML_ATTRIBUTE_CLASS; sub __get_attr_class { return $XML_ATTRIBUTE_CLASS; } use Class::Std::Fast::Storable constructor => 'none'; use base qw(SOAP::WSDL::XSD::Typelib::ComplexType); Class::Std::initialize(); { # BLOCK to scope variables my %Category_of :ATTR(:get<Category>); __PACKAGE__->_factory( [ qw( Category ) ], { 'Category' => \%Category_of, }, { 'Category' => 'MobPayTypes::ClassificationType::_Category', }, { 'Category' => 'Category', } ); } # end BLOCK package MobPayTypes::ClassificationType::_Category; use strict; use warnings; { # derivation by restriction use base qw( SOAP::WSDL::XSD::Typelib::Builtin::string); } 1; =pod =head1 NAME MobPayTypes::ClassificationType =head1 DESCRIPTION Perl data type class for the XML Schema defined complexType ClassificationType from the namespace http://www.mycompany.com/schema/common. =head2 PROPERTIES The following properties may be accessed using get_PROPERTY / set_PROPERTY methods: =over =item * Category =back =head1 METHODS =head2 new Constructor. The following data structure may be passed to new(): { # MobPayTypes::ClassificationType Category => $some_value, # atomic }, =head1 AUTHOR Generated by SOAP::WSDL =cut


Note I have snipped out some of the complexity from the post, please let me know if you need any more information, really appreciate the help,
regards
tubby
Direct Responses: 10449 | Write a response
Posted on 2009-04-08 10:18:12-07 by tubby in response to 10448
Re: Problem with using more than one XML Namespace
Hi Martin

I've been having a look at the generated classes, and I hope I haven't confused this issue by simplifying my question in a way that obscured the problem.
I can see some generated types that have a namespace set (via the get_xmlns() method), e.g

package MobPayTypes::ConsumerTransportType; use strict; use warnings; sub get_xmlns { 'http://www.mycompany.com/schema/common'}; # derivation by restriction use base qw( SOAP::WSDL::XSD::Typelib::Builtin::string); 1; __END__ =pod =head1 NAME =head1 DESCRIPTION Perl data type class for the XML Schema defined simpleType ConsumerTransportType from the namespace http://www.dialogue.net/mobpay/schema/common.

This is a simple type. The example that I have a problem with is a complex type with 2 or more sub elements. This is missing the get_xmlns() method

Here is the ClassificationType in full
package MobPayTypes::ClassificationType; use strict; use warnings; __PACKAGE__->_set_element_form_qualified(0); our $XML_ATTRIBUTE_CLASS; undef $XML_ATTRIBUTE_CLASS; sub __get_attr_class { return $XML_ATTRIBUTE_CLASS; } use Class::Std::Fast::Storable constructor => 'none'; use base qw(SOAP::WSDL::XSD::Typelib::ComplexType); Class::Std::initialize(); { # BLOCK to scope variables my %Category_of :ATTR(:get<Category>); my %Adult_of :ATTR(:get<Adult>); __PACKAGE__->_factory( [ qw( Category Adult ) ], { 'Category' => \%Category_of, 'Adult' => \%Adult_of, }, { 'Category' => 'MobPayTypes::ClassificationType::_Category', 'Adult' => 'SOAP::WSDL::XSD::Typelib::Builtin::boolean', }, { 'Category' => 'Category', 'Adult' => 'Adult', } ); } # end BLOCK package MobPayTypes::ClassificationType::_Category; use strict; use warnings; { # derivation by restriction use base qw( SOAP::WSDL::XSD::Typelib::Builtin::string); } 1; =pod =head1 NAME MobPayTypes::ClassificationType =head1 DESCRIPTION Perl data type class for the XML Schema defined complexType ClassificationType from the namespace http://www.mycompany.com/schema/common.

I have played with adding the get_xmlns() method into both the ClassificationType and the inner class _Category with no visible success.

Sorry for any bad info.
regards,
tubby
Direct Responses: 10465 | Write a response
Posted on 2009-04-09 19:36:26-07 by mkutter in response to 10449
Re: Problem with using more than one XML Namespace
Hi tubby,
Unfortunately I don't know exactly what's going on - it could have something to do with the element_form_qualified(0) (which SOAP::WSDL interprets incorrectly if not set in the WSDL - the default is true, and SOAP::WSDL defaults to false). You might want to set it in the WSDL if it's not set (the elementFormQualified attribute on xs:schema).

If this fails, can you send me the WSDL (via E-Mail - you find it in the POD).
Martin
Direct Responses: 10485 | Write a response
Posted on 2009-04-14 13:12:04-07 by tubby in response to 10465
Re: Problem with using more than one XML Namespace
Thanks Martin,
tried to do as you suggested, have emailed wsdl to you directly.
tubby
Direct Responses: 10486 | Write a response
Posted on 2009-04-14 20:30:28-07 by mkutter in response to 10485
Re: Problem with using more than one XML Namespace
Hi,
I've filed this as https://rt.cpan.org/Ticket/Display.html?id=45037
Should be fixed in SVN in Revision 847
Direct Responses: 10489 | Write a response
Posted on 2009-04-15 09:04:27-07 by tubby in response to 10486
Re: Problem with using more than one XML Namespace
Hi Martin,

Thanks for your fix, just checked out and built the latest SVN of SOAP::WSDL.
After running the new wsdl2perl.pl I can see the diffs. all the new Types have the get_xmlns method, so this seems to be good.

However, when I try and run the new code against the web service I still get a server side error:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body> <soapenv:Fault> <faultcode>soapenv:Client</faultcode> <faultstring xml:lang="en">INVALID_REQUEST</faultstring> <detail> <ServiceFault xmlns="http://www.mycompany.org/schema/common"> <StatusCode xmlns="http://www.mycompany.org/schema/common">INVALID_REQUEST</Sta +tusCode> <Reason xmlns="http://www.mycompany.org/schema/common">cvc-complex-type.2.4.a: +Invalid content was found starting with element 'Category'. One of '{"http://www.mycompany.org/sch +ema/common":Category}' is expected.</Reason> <Reason xmlns="http://www.mycompany.org/schema/common">cvc-complex-type.2.4.a: +Invalid content was found starting with element 'CurrencyCode'. One of '{"http://www.mycompany.org +/schema/common":CurrencyCode}' is expected.</Reason> </ServiceFault> </detail> </soapenv:Fault> </soapenv:Body> </soapenv:Envelope>

Here is the SOAP envelope being sent:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www +.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <DirectCharge xmlns="http://www.mycompany.org/schema/charging"> <ProductCode xmlns="http://www.mycompany.org/schema/charging">prod1</ProductCode> <ProductDescription xmlns="http://www.mycompany.org/schema/charging">someDescription</P +roductDescription> <Classification xmlns="http://www.mycompany.org/schema/charging"> <Category xmlns="">BUSINESS_SERVICES</Category> <Adult xmlns="">false</Adult> </Classification> <Cost xmlns="http://www.mycompany.org/schema/charging"> <CurrencyCode xmlns="">ZAR</CurrencyCode> <MonetaryValue xmlns="">1.50</MonetaryValue> </Cost> <ConsumerIdentity xmlns="http://www.mycompany.org/schema/charging">27711234567</Consume +rIdentity> </DirectCharge> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

It looks like the elements within the Classification and Cost elements are still getting a blank namespace, while the original SOAP UI example sets it to the common xsd schema, i.e:
<char:Classification> <com:Category>BUSINESS_SERVICES</com:Category> <com:Adult>false</com:Adult> </char:Classification>

Thanks again for your help so far,
tubby
Direct Responses: 10490 | Write a response
Posted on 2009-04-15 17:19:47-07 by mkutter in response to 10489
Re: Problem with using more than one XML Namespace
I'll have to check this with the original schema and WSDL - I'll need a few days to get it done...
Martin
Direct Responses: 10491 | Write a response
Posted on 2009-04-15 17:44:31-07 by mkutter in response to 10490
Re: Problem with using more than one XML Namespace
OK, that's another bug, though the workaround is easy.

SOAP::WSDL does not propagate the elementFormDefault attribute of imported schemata correctly, but sets it from the importing schema.

Just change the WSDL to look like this:
... <xsd:schema targetNamespace="http://www.dialogue.net/mobpay" elementFormDefault="qualified"> <xsd:import ... ...
This does no harm, and will not have any side effects once this error is fixed.

Martin
Direct Responses: 10502 | Write a response
Posted on 2009-04-20 12:45:41-07 by tubby in response to 10491
Re: Problem with using more than one XML Namespace
Hi Martin,

Would just like to confirm that your workaround sorts the namespace problem.
Again, thanks for your help so far, look forward to a fix in svn at some point
tubby
Direct Responses: Write a response