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

Hello Monks,

I'm having some issues both in using and understanding the nuances of SOAP::Lite. I'm trying to connect to our web service which is using WSDL, get a valid token, and return that token.

I get the following error when I run the script.

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

Here's the script below (with some elments X'd out).
#!/usr/bin/perl use SOAP::Lite +trace => 'debug'; use strict; use warnings; my $username = 'xxxxxx'; my $password = 'xxxxxx'; my $service = SOAP::Lite -> uri('http://xx-xx.xxxxxx.com/xxxws/xxxws?WSDL') -> proxy('http://ws.xxxxxx.com:80/xxxws') ; my $data = SOAP::Data ->name("GetToken" => \SOAP::Data->value( SOAP::Data->name("username" =>'$username'), SOAP::Data->name("password" => '$password') ) ); my $result = $service->call( SOAP::Data ->name('getToken') => $data ); print $result;

The output is below (I did not paste the HTML dump it gives of the elements (IE getToken, getEntitlements, ect).

SOAP::Transport::HTTP::Client::send_receive: POST
http://ws.xxxxxxx.com:80/xxxws HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 513
Content-Type: text/xml; charset=utf-8
SOAPAction: "#getToken"

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><getToken><GetToken><username xsi:type="xsd:string">$username</username><password xsi:type="xsd:string">$password</password></GetToken></getToken></soap:Body></soap:Envelope>
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
Cache-Control: no-cache="set-cookie"
Cache-Control: no-cache="set-cookie"
Connection: Close
Date: Wed, 09 Dec 2015 19:26:08 GMT
Server: Apache-Coyote/1.1
Content-Length: 2167
Content-Type: text/html;charset=ISO-8859-1
Content-Type: text/html; charset=UTF-8
Client-Date: Wed, 09 Dec 2015 19:26:08 GMT
Client-Peer: 54.85.177.107:80
Client-Response-Num: 1
Link: </xxxws/?stylesheet=1>; rel="stylesheet";
type="text/css"
Set-Cookie: AWSELB=xxxxxx;PATH=/;MAX-AGE=30
Set-Cookie: AWSELB=xxxxxx;PATH=/;MAX-AGE=30
Title: CXF - Service list


I think I need to use the namespace somewhere but not sure "where" that is. I've tried a few attempts (well, more then a few) but no luck.

I see from our WSDL page the targetNameSpace is as follows: java:com.xx.xxxws.parameters

I'll keep trying but hoping that you might bestow upon me some small measure of Perl's satori. Thank you.

Kevin M

Replies are listed 'Best First'.
Re: SOAP::Lite and getting error "not well-formed (invalid token)"
by tangent (Parson) on Dec 09, 2015 at 22:23 UTC
    May not solve your problem but where you have:
    SOAP::Data->name("username" =>'$username'), SOAP::Data->name("password" => '$password')
    is not doing what you want - the single quotes mean that the text '$username' is passed in literally when you want the actual values passed - just remove the quotes:
    SOAP::Data->name("username" => $username ), SOAP::Data->name("password" => $password )
    In fact you don't need the quotes on the left side either so this works too:
    SOAP::Data->name( username => $username ), SOAP::Data->name( password => $password )
      The OP's output shows that this, in fact, is a problem (May not be the only one), since it contains the strings $username and $password:
      ...<username xsi:type="xsd:string">$username</username> <password xsi:type="xsd:string">$password

              Our business is run on trust. We trust you will pay in advance.

Re: SOAP::Lite and getting error "not well-formed (invalid token)"
by Anonymous Monk on Dec 10, 2015 at 01:31 UTC

    Why do you think the problem is with your script?

    The SOAP server you're contacting is spitting out not well formed XML

    But you don't show that xml

    Anyway for debugging purposes you want use SOAP::Lite +trace => 'debug', readable => 1;

    See also XML::Compile::SOAP and soap tips and stuff...

      Gave up and went /w system tick and curl. Will try again when I have more time. Thank you for the tips btw! I had the wrong name space and fixed that but still no luck (same error).