Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

SOAP::LITE client help

by Wroof (Novice)
on Apr 30, 2014 at 23:44 UTC ( #1084556=perlquestion: print w/replies, xml ) Need Help??

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

Good morning Monks

I have been trying to write a client to access a soap server for a job and am very new to Perl and SOAP. I have been given the following information from the server and need to write a client for it. If someone use their vast knowledge to help me access the first function then I am sure I can take the rest :)

SOAP 1.1 HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getCardInfoResponse xmlns="http://www.designa.de/"> <getCardInfoResult> <AmountPayed>int</AmountPayed> <AmountDue>int</AmountDue> <AmountDueCurrency>decimal</AmountDueCurrency> <AmountDuePeriodStart>dateTime</AmountDuePeriodStart> <AmountDuePeriodEnd>dateTime</AmountDuePeriodEnd> <CardUID>guid</CardUID> <ISONumber>string</ISONumber> <CardType>int</CardType> <CarparkUID>guid</CarparkUID> <CarparkNr>int</CarparkNr> <CodingTime>dateTime</CodingTime> <LastTccNumber>int</LastTccNumber> <LastTccTime>dateTime</LastTccTime> <NumberOfPayments>int</NumberOfPayments> <GracePeriod>int</GracePeriod> <VAT>int</VAT> <MoneyConversionFactor>decimal</MoneyConversionFactor> <Currency>string</Currency> <Cheater>boolean</Cheater> <RabattInfo> <Wert>int</Wert> <Zeit>int</Zeit> <Promille>int</Promille> <PromilleGeb>int</PromilleGeb> <GID>int</GID> <NullUntil>int</NullUntil> <CaOrder>string</CaOrder> <WertVerr>int</WertVerr> <ZeitVerr>int</ZeitVerr> <RabattBetragAbsolut>int</RabattBetragAbsolut> </RabattInfo> </getCardInfoResult> </getCardInfoResponse> </soap:Body> </soap:Envelope> SOAP 1.2 HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <getCardInfoResponse xmlns="http://www.designa.de/"> <getCardInfoResult> <AmountPayed>int</AmountPayed> <AmountDue>int</AmountDue> <AmountDueCurrency>decimal</AmountDueCurrency> <AmountDuePeriodStart>dateTime</AmountDuePeriodStart> <AmountDuePeriodEnd>dateTime</AmountDuePeriodEnd> <CardUID>guid</CardUID> <ISONumber>string</ISONumber> <CardType>int</CardType> <CarparkUID>guid</CarparkUID> <CarparkNr>int</CarparkNr> <CodingTime>dateTime</CodingTime> <LastTccNumber>int</LastTccNumber> <LastTccTime>dateTime</LastTccTime> <NumberOfPayments>int</NumberOfPayments> <GracePeriod>int</GracePeriod> <VAT>int</VAT> <MoneyConversionFactor>decimal</MoneyConversionFactor> <Currency>string</Currency> <Cheater>boolean</Cheater> <RabattInfo> <Wert>int</Wert> <Zeit>int</Zeit> <Promille>int</Promille> <PromilleGeb>int</PromilleGeb> <GID>int</GID> <NullUntil>int</NullUntil> <CaOrder>string</CaOrder> <WertVerr>int</WertVerr> <ZeitVerr>int</ZeitVerr> <RabattBetragAbsolut>int</RabattBetragAbsolut> </RabattInfo> </getCardInfoResult> </getCardInfoResponse> </soap12:Body> </soap12:Envelope> HTTP POST HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <CardInfo xmlns="http://www.designa.de/"> <AmountPayed>int</AmountPayed> <AmountDue>int</AmountDue> <AmountDueCurrency>decimal</AmountDueCurrency> <AmountDuePeriodStart>dateTime</AmountDuePeriodStart> <AmountDuePeriodEnd>dateTime</AmountDuePeriodEnd> <CardUID>guid</CardUID> <ISONumber>string</ISONumber> <CardType>int</CardType> <CarparkUID>guid</CarparkUID> <CarparkNr>int</CarparkNr> <CodingTime>dateTime</CodingTime> <LastTccNumber>int</LastTccNumber> <LastTccTime>dateTime</LastTccTime> <NumberOfPayments>int</NumberOfPayments> <GracePeriod>int</GracePeriod> <VAT>int</VAT> <MoneyConversionFactor>decimal</MoneyConversionFactor> <Currency>string</Currency> <Cheater>boolean</Cheater> <RabattInfo> <Wert>int</Wert> <Zeit>int</Zeit> <Promille>int</Promille> <PromilleGeb>int</PromilleGeb> <GID>int</GID> <NullUntil>int</NullUntil> <CaOrder>string</CaOrder> <WertVerr>int</WertVerr> <ZeitVerr>int</ZeitVerr> <RabattBetragAbsolut>int</RabattBetragAbsolut> </RabattInfo> </CardInfo>

So far I have not even been able to create the most basic connection using Perl and am a complete loss as to what to do next. Below is my code to call the method isAlive that the server also has.

my ($isbn_number) = @ARGV; use SOAP::Lite +autodispatch=> uri=>'http://www.designa.de/', outputxml=>1, proxy=>'http://192.168.1.100/AbacusWebService/ServiceCashPoint.a +smx'; my $isbn_xml = isAlive(); print "$isbn_xml\n";

As you can probably tell I have modified this from an example. Below is the output I get

Use of inherited AUTOLOAD for non-method main::isAlive() is deprecate +d at C:\Use rs\Sam\Documents\Perl code\soap.pl line 15. <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http: +//schemas. xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchem +a-instance " xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault> +<faultcode >soap:Client</faultcode><faultstring>Server did not recognize the valu +e of HTTP Header SOAPAction: http://www.designa.de/#isAlive.</faultstring><detai +l /></soap :Fault></soap:Body></soap:Envelope> Press any key to continue . . .

Replies are listed 'Best First'.
Re: SOAP::LITE client help
by Khen1950fx (Canon) on May 01, 2014 at 04:24 UTC
    In general, I would try something along these lines; also, you'll need warnings::everywhere.
    #!/usr/bin/perl -l use strict; no warnings::anywhere qw(deprecated); use warnings qw(deprecated); my $isbn = shift @ARGV; use SOAP::Lite +autodispatch => uri => 'http://www.designa.de/', proxy => 'http://192.168.1.100/AbacusWebService/ServiceCashPoint.a +smx', on_fault => sub { my ( $soap, $res ) = @_; die ref $res ? $res->faultdetail : $soap->transport->status; }; isAlive( $isbn ); print SOAP::Lite->self->call->result;
    Update: fixed typo - should be a comma at end of line 11.

      Thanks for your help. When I try and run this code after installing warnings::Everywhere I get the following errors.

      Use of uninitialized value $_[0] in pattern match (m//) at C:/Strawber +ry/perl/si te/lib/SOAP/Lite.pm line 340. Use of uninitialized value in sprintf at C:/Strawberry/perl/site/lib/S +OAP/Lite.p m line 3612. Press any key to continue . . .

      I have also tried another piece of code to see what happens and this one returns no errors but it also does not output anything other that the test points I put in. This uses the WSDL on the page.

      #!/usr/bin/perl -w use strict; use diagnostics; use warnings; use Data::Dumper; eval { require SOAP::Lite; }; die "Fehler:\n$@\n\n" if $@; my $soap = SOAP::Lite->new(); print "test \n"; my $service = $soap->service('http://192.168.1.100/AbacusWebService/Se +rviceCashPoint.asmx?wsdl'); print Dumper($service->getCardInfo('ws','ws','45','pm01001011000000003 +7')); print "test \n";
        Thanks for the response. I fixed a typo. Please try it again.
Re: SOAP::LITE client help
by Anonymous Monk on May 01, 2014 at 02:35 UTC
Re: SOAP::LITE client help
by Wroof (Novice) on May 02, 2014 at 01:28 UTC

    Ok so thank you everyone for you help so far. Currently I have not have not been able to get much back from the system so I have decided to try the html approach in Perl. Below is the code

    #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request::Common; my $userAgent = LWP::UserAgent->new(agent => 'perl post'); my $message = "<?xml version=\"1.0\" encoding=\"utf-8\"?> <soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance +\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\"> <soap12:Body> <getCardInfo xmlns=\"http://www.designa.de/\"> <UserID>ws</UserID> <UserPWD>ws</UserPWD> <TccNum>45</TccNum> <CardNumber>\"PM010010110000000037\"</CardNumber> </getCardInfo> </soap12:Body> </soap12:Envelope>" ; my $response = $userAgent->request(POST 'http://192.168.1.100/AbacusWe +bService/ServiceCashPoint.asmx/getCardInfo', Content_Type => 'text/plain', Content => $message); print $response->error_as_HTML unless $response->is_success; print $response->as_string;

    Now I can connect for the isAlive command and get a response bac even though it is in a xml format. How ever when I try and and request getCardInfo which is to return a few different things I get a error saying Request format is invalid. I know I am missing something simple but for the life of me I cannot work it out. Once again thanks for all the help

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1084556]
Approved by rnewsham
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2019-07-18 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?