ffrost has asked for the wisdom of the Perl Monks concerning the following question:

Hoping this is an easy problem to solve as my attempts are failing miserably. Using the AI bots and Google only seem to create solutions where the output is all mungled up or the XML elements get repeated, or worse new XML elements are added.

In short, I'm creating a specific soap envelope I need to send to the endpoint web service. The reason is due to complexity and the inability for SOAP::Lite to render the output correctly. This also provides more control for changes as they occur. But when I try to make the call to the web service and send the envelope it seems to be sending the data modified, or the method call is not correct, etc.

I'll post an example below and hopefully someone has a 'duh' answer I seem to be missing.

use SOAP::Lite; use SOAP::Lite on_action => sub {sprintf '%s/%s',@_}; $proxy = 'https://proxy.com/2.3'; $uri = 'https://uri.dataservices.training'; $method = 'methodCall'; $soap = SOAP::Lite ->proxy($proxy) ->uri($uri); $soapenv = <<'EOF'; <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope ... (bunch of NS values)> <soap:Header> (bunch of header settings here) </soap:Header> <soap:Body> (bunch of body settings here) </soap:Body> </soap:Envelope> EOF $results = $soap->call("$uri/$method",$soapenv);

This is resulting in the error "Element ..($uri/$method) ... can't be allowed in valid XML message.

Replies are listed 'Best First'.
Re: sending raw soap envelope with soap::lite
by stevieb (Canon) on Nov 29, 2023 at 19:04 UTC

    I've never used a SOAP interface before, but I did spot something.

    You have this, which I would suspect sets up the object with the URI:

    $soap = SOAP::Lite ->proxy($proxy) ->uri($uri);

    But then when you make the call, you include the URI again:

    $results = $soap->call("$uri/$method",$soapenv);

    What happens if you included only the method in the call?:

    $results = $soap->call($method, $soapenv);
      What happens if you included only the method in the call?: $results = $soap->call($method, $soapenv);

      answer: I get a SOAP envelope going to the web service with munged up XML. For example:

      <soap:Envelope ...> <soap:Body> ... <c-gensym2><?xml version="1.0" encoding="UTF-8"> <soap:Envelope ...> <soap:Header> ... </soap:Header> <soap:Body> ... </soap:Body> </soap:Envelope> </c-gensym2> </soap:Body> </soap:Envelope>