I'm pretty new to SOAP. I've been using SOAP::Lite to generate SOAP messages for a vendor-provided service inside our corporate firewall. For messages with simple types, I've gotten it to work, although it has involved a lot of trial and error before I got the XML formatted the way the service was expecting it.

Now I'm running into trouble generating a SOAP message with a complex type (basically an array of min and max integer values which represent ranges of numbers). The fault codes I'm getting back when my message fails are pretty useless: soap:Server in the fault code, a bunch of useless (to me, anyway) java error messages in the stacktrace, and a 500 internal server error in the SOAP::Transport response. I asked the vendor to write their service so it can accept whatever and respond in a more helpful manner (telling me if my XML was malformed, specifically showing which element had problems, etc.). They respond:

"The arguments which are passed from the SOAP client are first decoded before reaching the application. The format and data types need to match what is expected in the wdsl file."

Is there a way for me to prevalidate my XML against the WSDL? I see (or interpret, anyway) that SOAP::Lite doesn't support WSDLs with complex types ... is there another way to skin this cat? It seems like a cop-out for the vendor to defer all error handling to the WSDL if there is no way for me to verify my XML against the WSDL ... or am I misunderstanding the purpose of the WSDL?

Just for context, I'm creating my SOAP connection in this manner (I've left out some of the proprietary stuff), and executing the 'add' method as follows:

sub build_SOAP_connection { my $self = shift; my $ns = $self->{'data'}->{'namespace'}; my $ep = $self->{'data'}->{'proxy'}; my $lite = SOAP::Lite->uri($ns)->proxy($ep)->on_action( sub { join " +", @_ } ); $lite->autotype(0); $lite->soapversion('1.1'); $lite->serializer()->namespaces({ 'http://schemas.xmlsoap.org/soap/envelope/' => 'soap', 'http://schemas.xmlsoap.org/soap/envelope/' => 'soapenv', 'http://schemas.xmlsoap.org/soap/encoding/' => 'soapenc', 'http://www.w3.org/2001/XMLSchema' => 'xsd', 'http://www.w3.org/2001/XMLSchema-instance' => 'xsi' }); $self->{'SOAP'} = $lite; return $lite; } sub SOAP_execute { my $self = shift; my $method = shift; my $datagram = shift; my $SOAP; if (exists($self->{'SOAP'})) { $SOAP = $self->{'SOAP'}; } else { $SOAP = $self->build_SOAP_connection(); } my $doc = SOAP::Data->name($method)->uri($self->{'data'}->{'namespac +e'})->prefix(''); my $response; eval { $response = $SOAP->call($doc => $datagram); }; if ($@) { print "Error: $method SOAP call died: $@.\n"; return 1; } if ($response->fault) { print "Fault code: ", $response->faultcode, "\n"; print "Fault string: ", $response->faultstring, "\n"; print "Fault actor: ", $response->faultactor, "\n"; return $response->faultcode; } else { my $body = $response->result; # returns the first object unless ($body == 0) { $self->{'data'}->{'ERROR'} = "ERROR: method $method failed: $bod +y"; } return $body; } }

Should I push back to the vendor and require them to respond with decent error messages if my XML is badly formed or typed, or is their position reasonable and I simply need to figure out how to validate my own messages? Advice on validating my XML against the WSDL is particularly welcome.


No good deed goes unpunished. -- (attributed to) Oscar Wilde

2006-04-08 Retitled by planetscape, as per Monastery guidelines
Original title: 'OT: Validating SOAP with a WSDL'


In reply to Validating SOAP with a WSDL by ptum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.