PERLfisher
asked on
SOAP::LITE - Incorporating XML file into Soap Message
Hi,
I am trying to send a SOAP message which incorporates an XML file but am getting an error message.
Here is the XML file I want to incorporate:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.pip.crif.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><SOAP-ENV:Body><mns1:getH ospitalsLi st xmlns:mns1="http://ws.pip.crif.com/"><hospitalNam e></hospit alName><po stCode></p ostCode><u serAuth><a sUser>COMP 028_ch</as User><pass word>psw02 8a2a</pass word><user name>COMP0 28_a2a</us ername></u serAuth></ mns1:getHo spitalsLis t></SOAP-E NV:Body></ SOAP-ENV:E nvelope>
Here is my script:
#!/usr/bin/perl
###my $WSDL="https://site.net/PosGatewayService.asmx?wsdl=wsdl1";
my $NS = "http://ws.pip.crif.com/";
my $HOST = "http://piptesta2a.crif.com:80/PIP.WS/PIPWS";
use strict;
use SOAP::Lite +trace => qw (debug);
my $soap = SOAP::Lite
#->readable(1)
->xmlschema('http://www.w3.org/2001/XMLSchema')
->on_action( sub { join '/', 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS', $_[1]} )
->proxy($HOST)
->uri($NS);
my $method;
open(my $in, "<getHospitalsList_Request 2.txt") or die "Could not open xml: $!\n";
{
local $/;
$method=<$in>;
}
close($in);
my $results = $soap->call($method);
The error message is below.
I don't really understand the error message as there's nothing wrong with my XML, however there is an odd character just before the first element. Can anyone help?
untitled.bmp
I am trying to send a SOAP message which incorporates an XML file but am getting an error message.
Here is the XML file I want to incorporate:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.pip.crif.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><SOAP-ENV:Body><mns1:getH
Here is my script:
#!/usr/bin/perl
###my $WSDL="https://site.net/PosGatewayService.asmx?wsdl=wsdl1";
my $NS = "http://ws.pip.crif.com/";
my $HOST = "http://piptesta2a.crif.com:80/PIP.WS/PIPWS";
use strict;
use SOAP::Lite +trace => qw (debug);
my $soap = SOAP::Lite
#->readable(1)
->xmlschema('http://www.w3.org/2001/XMLSchema')
->on_action( sub { join '/', 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS', $_[1]} )
->proxy($HOST)
->uri($NS);
my $method;
open(my $in, "<getHospitalsList_Request
{
local $/;
$method=<$in>;
}
close($in);
my $results = $soap->call($method);
The error message is below.
I don't really understand the error message as there's nothing wrong with my XML, however there is an odd character just before the first element. Can anyone help?
untitled.bmp
ASKER
How do I declare $service?
ASKER
Ok, I have amended my script so it is now as follows:
#!/usr/bin/perl
my $NS = "http://ws.pip.crif.com/";
my $HOST = "http://piptesta2a.crif.com:80/PIP.WS/PIPWS";
my $service = ( sub { join '/', 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS', $_[1]} );
#use strict;
use SOAP::Lite ( +trace => all, maptype => {} );
my $soap = SOAP::Lite
#->readable(1)
->xmlschema('http://www.w3.org/2001/XMLSchema')
#->on_action( sub { return 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS'})
->on_action( sub { join '/', 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS', $_[1]} )
->proxy($HOST)
->uri($NS);
# ->service($service);
my $method;
open(my $in, "<getHospitalsList_Request 2.xml") or die "Could not open xml: $!\n";
{local $/;
$method=<$in>; }
close($in);
my $result = $soap ->$service( SOAP::Data->type( 'string' => "$method" ) )->result;
#my $resultsfile = "results.txt";
#open FILE, ">$resultsfile" or die "unable to open $resultsfile $!";
#print FILE $method;
I am now getting the error message attached
#!/usr/bin/perl
my $NS = "http://ws.pip.crif.com/";
my $HOST = "http://piptesta2a.crif.com:80/PIP.WS/PIPWS";
my $service = ( sub { join '/', 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS', $_[1]} );
#use strict;
use SOAP::Lite ( +trace => all, maptype => {} );
my $soap = SOAP::Lite
#->readable(1)
->xmlschema('http://www.w3.org/2001/XMLSchema')
#->on_action( sub { return 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS'})
->on_action( sub { join '/', 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS', $_[1]} )
->proxy($HOST)
->uri($NS);
# ->service($service);
my $method;
open(my $in, "<getHospitalsList_Request
{local $/;
$method=<$in>; }
close($in);
my $result = $soap ->$service( SOAP::Data->type( 'string' => "$method" ) )->result;
#my $resultsfile = "results.txt";
#open FILE, ">$resultsfile" or die "unable to open $resultsfile $!";
#print FILE $method;
I am now getting the error message attached
ASKER
Error message attached:
Message-2.bmp
Message-2.bmp
ASKER
I think I am now very close!
This is my code:
#!/usr/bin/perl
my $NS = "http://ws.pip.crif.com/";
my $HOST = "http://piptesta2a.crif.com:80/PIP.WS/PIPWS";
my $service = "http://piptesta2a.crif.com/PIP.WS/PIPWS?wsdl";
use strict;
use SOAP::Lite +trace => qw (debug);
my $soap = SOAP::Lite
->xmlschema('http://www.w3.org/2001/XMLSchema')
->on_action( sub { join '/', 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS', $_[1]} )
->proxy($HOST)
->service($service)
->uri($NS);
my $method;
open(my $in, "<getHospitalsList_Request 2.xml") or die "Could not open xml: $!\n";
{
local $/;
$method=<$in>;
}
close($in);
my $result = $soap ->$service( SOAP::Data->type( 'string' => "$method" ) )->result;
I seem to be "hitting" the server ok but it is not happy with the name of my method as it is displaying this message:
"Unrecognised method 'http://piptesta2a.crif.com/PIP.WS/PIPWS?wsdl', followed by a list of the available methods. The one I want to call is 'getHospitalsList' and it appears in the list, but whenever I try to reference it specifically
e.g. my $service = "http://piptesta2a.crif.com/PIP.WS/PIPWS?wsdl/getHospitalsList";
I get the same error message.
Help!!!
This is my code:
#!/usr/bin/perl
my $NS = "http://ws.pip.crif.com/";
my $HOST = "http://piptesta2a.crif.com:80/PIP.WS/PIPWS";
my $service = "http://piptesta2a.crif.com/PIP.WS/PIPWS?wsdl";
use strict;
use SOAP::Lite +trace => qw (debug);
my $soap = SOAP::Lite
->xmlschema('http://www.w3.org/2001/XMLSchema')
->on_action( sub { join '/', 'http://piptesta2a.crif.com:80/PIP.WS/PIPWS', $_[1]} )
->proxy($HOST)
->service($service)
->uri($NS);
my $method;
open(my $in, "<getHospitalsList_Request
{
local $/;
$method=<$in>;
}
close($in);
my $result = $soap ->$service( SOAP::Data->type( 'string' => "$method" ) )->result;
I seem to be "hitting" the server ok but it is not happy with the name of my method as it is displaying this message:
"Unrecognised method 'http://piptesta2a.crif.com/PIP.WS/PIPWS?wsdl', followed by a list of the available methods. The one I want to call is 'getHospitalsList' and it appears in the list, but whenever I try to reference it specifically
e.g. my $service = "http://piptesta2a.crif.com/PIP.WS/PIPWS?wsdl/getHospitalsList";
I get the same error message.
Help!!!
$service should be getHospitalsList and not the whole URI
ASKER
Yes, but I have tried getHospitalsList on its own and I get a "URL must be absolute" message.
ASKER
The service (getHospitalsList) is a complextype, does that make any difference?
my $NS = "http://ws.pip.crif.com/";
my $HOST = "http://piptesta2a.crif.com:80/PIP.WS/PIPWS";
my $service = 'getHospitalsList';
my $soap = SOAP::Lite->uri($NS)->proxy($HOST)->on_fault(
sub {
my $soap = shift;
my $res = shift;
my $msg =
ref $res
? "--- SOAP FAULT ---\n"
. $res->faultcode . " "
. $res->faultstring
: "--- TRANSPORT ERROR ---\n"
. $soap->transport->status
. "\n$res\n";
die $msg;
}
);
my $method;
open(my $in, "<getHospitalsList_Request2.xml") or die "Could not open xml: $!\n";
{
local $/;
$method=<$in>;
}
close($in);
print $soap ->$service( SOAP::Data->type( 'string' => "$method" ) )->result;
ASKER
I copied and pasted your code:
Message-3.bmp
Message-3.bmp
your input is incorrect ... can you paste the file that you are sending the webservice?
ASKER
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.pip.crif.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><SOAP-ENV:Body><mns1:getH ospitalsLi st xmlns:mns1="http://ws.pip.crif.com/"><hospitalNam e></hospit alName><po stCode></p ostCode><u serAuth><a sUser>COMP 028_ch</as User><pass word>psw02 8a2a</pass word><user name>COMP0 28_a2a</us ername></u serAuth></ mns1:getHo spitalsLis t></SOAP-E NV:Body></ SOAP-ENV:E nvelope>
Okay, that is the problem .. you are wrapping the soap message in a soap message ...
your file should only contain something like:
<mns1:getHospitalsList xmlns:mns1="http://ws.pip.crif.com/">
<hospitalName></hospitalNa me>
<postCode></postCode>
<userAuth>
<asUser>COMP028_ch</asUser >
<password>password_here</p assword>
<username>username_here</u sername>
</userAuth>
</mns1:getHospitalsList>
your file should only contain something like:
<mns1:getHospitalsList xmlns:mns1="http://ws.pip.crif.com/">
<hospitalName></hospitalNa
<postCode></postCode>
<userAuth>
<asUser>COMP028_ch</asUser
<password>password_here</p
<username>username_here</u
</userAuth>
</mns1:getHospitalsList>
ASKER
I have removed the envelope XML:
Message-4.bmp
Message-4.bmp
Sorry, I had tried to view the wsdl earlier, but failed ... Having just viewed it, your service is a document/literal web service. SOAP lite has limited support for doc lit services.
I would recommend that you use XML::Compile::SOAP (http://search.cpan.org/dist/XML-Compile-SOAP/)
They have pretty decent documentation (http://search.cpan.org/~markov/XML-Compile-SOAP-2.12/lib/XML/Compile/SOAP.pod#SYNOPSIS).
I would recommend that you use XML::Compile::SOAP (http://search.cpan.org/dist/XML-Compile-SOAP/)
They have pretty decent documentation (http://search.cpan.org/~markov/XML-Compile-SOAP-2.12/lib/XML/Compile/SOAP.pod#SYNOPSIS).
ASKER
Oh, I see...
I can't find XML::Compile::SOAP using ppm. Do you know why? I haven't tried to install a module without ppm before.
I can't find XML::Compile::SOAP using ppm. Do you know why? I haven't tried to install a module without ppm before.
Do you have to use windows? I noticed that ppm has an old version (not sure if it makes a huge difference though) of XML-Compile-SOAP (replace :: with -).
ASKER
I can't find it using my ppm.
I can download it via Windows, I just wondered where I should save it (Perl is on my C: drive)?
I can download it via Windows, I just wondered where I should save it (Perl is on my C: drive)?
Goto http://trouchelle.com/perl/ppmrepview.pl? and add the repo to ppm. Once you are done, install the module below:
SOAP-XML-Client (this is the module once you add the repo)
Once the module is installed, the following code should help you get started ... you need to modify some of the values and make sure that http://piptesta2a.crif.com/PIP.WS/PIPWS?wsdl is saved to a text file called pipws.wsdl in the directory that contains your script.
#!/usr/bin/perl -w
use strict;
use XML::Compile::WSDL11; # use WSDL version 1.1
use XML::Compile::SOAP11; # use SOAP version 1.1
use XML::Compile::Transport::SOAPHTTP;
use Data::Dumper;
my $wsdl = XML::Compile::WSDL11->new('pipws.wsdl');
# during initiation, for each used call (slow)
my $call = $wsdl->compileClient('getHospitalsList');
# at "run-time", call as often as you want (fast)
my $answer = $call->(hospitalName => '', postCode=> '', userAuth => {asUser => '', password => '', username => ''});
print Dumper($answer);
ASKER
I have downloaded SOAP-XML-CLIENT now. I will have a look at it and see if I can get to grips.
BTW, what is the significance of a document/literal web service?
BTW, what is the significance of a document/literal web service?
there are different flavours of SOAP, with each having their own ways of doing things. http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/ is a good reference.
ASKER
Success!
This worked:
#!/usr/bin/perl -w
use strict;
use XML::Compile::WSDL11; # use WSDL version 1.1
use XML::Compile::SOAP11; # use SOAP version 1.1
use XML::Compile::Transport::S OAPHTTP;
use Data::Dumper;
my $wsdl = XML::Compile::WSDL11->new( 'pipws(Sta ge1).wsdl' );
# during initiation, for each used call (slow)
my $call = $wsdl->compileClient('getH ospitalsLi st');
# at "run-time", call as often as you want (fast)
my $answer = $call->(hospitalName => 'Aberdeen', postCode => '', userAuth => {asUser => 'COMP028_ch', password => 'psw028a2a', username => 'COMP028_a2a'});
print Dumper($answer);
There are 2 things I'd like to change, though:
1. Currently the parameter values (hospitalName, userauth) are hard-coded, whereas I'd like to read them in from the XML file I posted earlier
2, I'd like to output the response to an XML file.
Is this straightforward?
This worked:
#!/usr/bin/perl -w
use strict;
use XML::Compile::WSDL11; # use WSDL version 1.1
use XML::Compile::SOAP11; # use SOAP version 1.1
use XML::Compile::Transport::S
use Data::Dumper;
my $wsdl = XML::Compile::WSDL11->new(
# during initiation, for each used call (slow)
my $call = $wsdl->compileClient('getH
# at "run-time", call as often as you want (fast)
my $answer = $call->(hospitalName => 'Aberdeen', postCode => '', userAuth => {asUser => 'COMP028_ch', password => 'psw028a2a', username => 'COMP028_a2a'});
print Dumper($answer);
There are 2 things I'd like to change, though:
1. Currently the parameter values (hospitalName, userauth) are hard-coded, whereas I'd like to read them in from the XML file I posted earlier
2, I'd like to output the response to an XML file.
Is this straightforward?
glad to hear that we solved the problem!
with regards to your changes,
1. you could read them in. many options available ... you could read in the XML file and use an XML parser to extract the values that you need. then create your $answer
2. writing a file is as easy as
open(OUTFILE, '>someFile.xml') or die $!;
print OUTFILE $answer->NOT_SURE_HERE;
close OUTFILE;
the NOT_SURE_HERE is the key of the hash of your dump ... if you print out the contents when you run the program, i will tell you exactly what you need.
with regards to your changes,
1. you could read them in. many options available ... you could read in the XML file and use an XML parser to extract the values that you need. then create your $answer
2. writing a file is as easy as
open(OUTFILE, '>someFile.xml') or die $!;
print OUTFILE $answer->NOT_SURE_HERE;
close OUTFILE;
the NOT_SURE_HERE is the key of the hash of your dump ... if you print out the contents when you run the program, i will tell you exactly what you need.
ASKER
Hi.
I have run the following code but am unable to print to my xml file; it looks as though I can't get values out of the hash as easily as I thought! The message output is attached.
#!/usr/bin/perl -w
use strict;
use XML::Compile::WSDL11; # use WSDL version 1.1
use XML::Compile::SOAP11; # use SOAP version 1.1
use XML::Compile::Transport::S OAPHTTP;
use Data::Dumper;
my $wsdl = XML::Compile::WSDL11->new( 'pipws(Sta ge1).wsdl' );
# during initiation, for each used call (slow)
my $call = $wsdl->compileClient('getH ospitalsLi st');
# at "run-time", call as often as you want (fast)
my $answer = $call->(hospitalName => 'Aberdeen', postCode => '', userAuth => {asUser => 'COMP028_ch', password => 'psw028a2a', username => 'COMP028_a2a'});
print Dumper($answer);
open(OUTFILE, '>someFile.xml') or die $!;
print OUTFILE $answer->{'name'}[1];
close OUTFILE;
Message-6.bmp
I have run the following code but am unable to print to my xml file; it looks as though I can't get values out of the hash as easily as I thought! The message output is attached.
#!/usr/bin/perl -w
use strict;
use XML::Compile::WSDL11; # use WSDL version 1.1
use XML::Compile::SOAP11; # use SOAP version 1.1
use XML::Compile::Transport::S
use Data::Dumper;
my $wsdl = XML::Compile::WSDL11->new(
# during initiation, for each used call (slow)
my $call = $wsdl->compileClient('getH
# at "run-time", call as often as you want (fast)
my $answer = $call->(hospitalName => 'Aberdeen', postCode => '', userAuth => {asUser => 'COMP028_ch', password => 'psw028a2a', username => 'COMP028_a2a'});
print Dumper($answer);
open(OUTFILE, '>someFile.xml') or die $!;
print OUTFILE $answer->{'name'}[1];
close OUTFILE;
Message-6.bmp
this one has the XML ... but my next comment will be better
#!/usr/bin/perl -w
use strict;
use XML::Compile::WSDL11; # use WSDL version 1.1
use XML::Compile::SOAP11; # use SOAP version 1.1
use XML::Compile::Transport::SOAPHTTP;
use Data::Dumper;
my $wsdl = XML::Compile::WSDL11->new('pipws(Stage1).wsdl');
# during initiation, for each used call (slow)
my $call = $wsdl->compileClient('getHospitalsList');
# at "run-time", call as often as you want (fast)
my ($answer, $trace) = $call->(hospitalName => 'Aberdeen', postCode => '', userAuth => {asUser => 'COMP028_ch', password => 'psw028a2a', username => 'COMP028_a2a'});
print Dumper($answer);
open(OUTFILE, '>someFile.xml') or die $!;
print OUTFILE $trace->response->content;
close OUTFILE;
#!/usr/bin/perl -w
use strict;
use XML::Compile::WSDL11; # use WSDL version 1.1
use XML::Compile::SOAP11; # use SOAP version 1.1
use XML::Compile::Transport::SOAPHTTP;
use Data::Dumper;
my $wsdl = XML::Compile::WSDL11->new('pipws.wsdl');
# during initiation, for each used call (slow)
my $call = $wsdl->compileClient('getHospitalsList');
# at "run-time", call as often as you want (fast)
my ($answer, $trace) = $call->(hospitalName => 'Aberdeen', postCode => '', userAuth => {asUser => 'COMP028_ch', password => 'psw028a2a', username => 'COMP028_a2a'});
print Dumper($answer);
my $output = '';
my $hospitals = $answer->{'getHospitalsListResponse'}->{'hospitalsListResponse'}->{'hospitalsList'};
foreach my $h (@$hospitals) {
$output .= '<hospitalsList>';
for my $key (keys %$h) {
$output = $output . "\n <$key>" . $h->{$key} . "</$key>";
}
$output .= "\n" . '</hospitalsList>' . "\n";
}
open(OUTFILE, '>someFile.xml') or die $!;
print OUTFILE $output;
close OUTFILE;
ASKER
This works brilliantly! I am so grateful for your help.
The only thing left is for me to be able to load the request parameters in from an XML file.
The only thing left is for me to be able to load the request parameters in from an XML file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will test this, many thanks.
ASKER
Fantastic help from Kawas
Open in new window