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

Hi,

I'm currently facing an XML Parsing issue right on the xml declaration (<?xml ...) with using SOAP::Lite.

not well-formed (invalid token) at line 1, column 3, byte 3 at /usr/lib64/perl5/vendor_perl/XML/Parser.pm line 187.

Context: using SOAP::Lite as client to request a service endpoint (WSDL web service) with WSSE security.

URI is not provided as an attribute for method (getListOfSesms) Use of uninitialized value $name in substitution (s///) at /usr/local/ +share/perl5/SOAP/Lite.pm line 1117. Use of uninitialized value $name in exists at /usr/local/share/perl5/S +OAP/Lite.pm line 1118. Use of uninitialized value $name in hash element at /usr/local/share/p +erl5/SOAP/Lite.pm line 1118. Use of uninitialized value $name in hash element at /usr/local/share/p +erl5/SOAP/Lite.pm line 1122. Use of uninitialized value $name in hash element at /usr/local/share/p +erl5/SOAP/Lite.pm line 1122. SOAP::Transport::HTTP::Client::send_receive: POST https://A.B.C.D:8443 +/prov/services/ConfigAdminService HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 1384 Content-Type: text/xml; charset=utf-8 SOAPAction: "#getListOfSesms" <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:con="config.ws.nortelnetworks.com" xmlns:namesp1="http://namespaces.soaplite.com/perl" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header> <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs. +oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd +" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss- +wssecurity-utility-1.0.xsd"> <wsse:UsernameToken wsu:Id="UsernameToken-B2BC1A8DAD33A413E21488 +9629128004"> <wsse:Username>XXXXXX</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oa +sis-200401-wss-username-token-profile-1.0#PasswordText">XXXXXX</wsse: +Password> <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/ +01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">YSB2YWx1Z +SBvZiA2OA==</wsse:Nonce> <wsu:Created>2017-03-10T09:12:51Z</wsu:Created> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <getListOfSesms soapenv:encodingStyle="http://schemas.xmlsoap.org/ +soap/encoding/" xsi:nil="true" /> </soapenv:Body> </soapenv:Envelope> SOAP::Transport::HTTP::Client::send_receive: 500 Can't connect to A.B. +C.D:8443 Content-Type: text/plain Client-Date: Fri, 10 Mar 2017 09:12:51 GMT Client-Warning: Internal response Can't connect to A.B.C.D:8443 not well-formed (invalid token) at line 1, column 3, byte 3 at /usr/li +b64/perl5/vendor_perl/XML/Parser.pm line 187. Can't connect to A.B.C.D:8443

For information:
- XML syntax from the trace above has been checked ok with some XML syntax tools
- I have used stubmaker to get WSDL into Perl (ConfigAdminIFService here)
- I had to use call() instead of method() to pass the authentication parameters ($auth)
- when using SOAPUI, there is no xml declaration in the request.

Some code extracts:

use strict; use utf8; use XML::Parser; use Time::Local; use Digest::SHA1; use MIME::Base64; use SOAP::Lite +trace => 'debug', readable => 1; use SOAP::WSDL; use ConfigAdminIFService; $SOAP::Constants::PREFIX_ENV = 'soapenv'; [...] my $service_url='https://A.B.C.D:8443/prov/services/ConfigAdminService +'; my $soap = new ConfigAdminIFService->new(); $soap->proxy($service_url); $soap->serializer->attr({ "xmlns:con" => "config.ws.nortelnetworks.com +" , "xmlns:soapenv" => "http://schemas.xmlsoap.org/soap/envelope/" }) +; $soap->readable(1); my $response = $soap->call( SOAP::Data ->name('getListOfSesms') ->attr({ "soapenv:encodingStyle" => "http://sc +hemas.xmlsoap.org/soap/encoding/" }), $auth);

I have run through various settings, including encoding, Content-Type, etc. without luck so far.
Also, would there be any option for removing the xml declaration as it is not present in the raw request when using SOAPUI ?
Thanks a lot for your previous help and advice
Erwan.

Replies are listed 'Best First'.
Re: XML Parsing issue with SOAP::Lite (xml declaration)
by hippo (Archbishop) on Mar 10, 2017 at 09:57 UTC
    Can't connect to A.B.C.D:8443

    Just in case you aren't seeing the wood for the trees - the above error message seems to suggest the real problem. If the process can't perform the HTTP connection then you surely won't be getting a parseable XML response back.

      Hi, the IP address has been hidden on purpose in the extract. Yet, your question makes me wonder whether the parsing issue on the request itself or in the response sent by the server. Is there any way i could find out ?

        If you get Client-Warning: Internal response, then LWP never talked to the remote server.

        So, there is an issue that A.B.C.D does not listen on 8443 from your host. Maybe you need a proxy.

        I would first debug the TCP connection from the client to the server on port 8443, by trying with another HTTP client like wget or curl.

Re: XML Parsing issue with SOAP::Lite (xml declaration)
by Anonymous Monk on Mar 10, 2017 at 10:25 UTC
      Hi, not sure whether SOAP::Lite supports WSS or not but i understood it only provides envelope framework to work with so i just passed the required wsse tags using SOAP::Data & Headers as soap headers so i get the properly formatted soap request.
      I guess this should work as well but will look at the threads you mentioned.