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

Hello guys,
i am trying to make a call to .net based API via SOAP::WSDL, first i need to
make a call with my user name and password, then if that will go
through fine, i will get back a communityID and cookie, and then i can
make another calls to same API, while i have my cookie set. Here is my
code that i currently have


#!/usr/bin/perl use SOAP::WSDL; use HTTP::Cookies; import SOAP::Lite +trace => 'all'; my $soap = SOAP::WSDL->new(wsdl => 'http://domain.tld/api.wsdl'); $soap->proxy('https://domain.level.tld/API/api.dll?Handler=Default', cookie_jar => HTTP::Cookies->new()); $soap->wsdlinit(caching=>1); $soap->call('SessionLoginTechnician', 'TechName' => 'username', 'Password' => 'password', ); $soap->call('AccountSetStatus', AccountNumber => 123456789, Status => 'ACCOUNT_ACTIVE', Justification => 'api testing', StatusCode => 0 );
first call goes very well, i am getting in return communityID that i am
expecting, however second call i am getting an eror message that is
telling me that i am not authenticated....

i see soap call and that is forming correctly, and i am even getting right
response from API with 4 digit error code (well i wish i would get that
response lol) i am assuming that i am not setting cookie correctly, or maybe i am totaly
missing something, please help me out guys :)

Replies are listed 'Best First'.
Re: help with setting cookie with SOAP::WSDL
by olus (Curate) on Dec 19, 2007 at 12:09 UTC
    Hi winfinit

    SOAP APIs usually require the authentication parameters on the SOAP envelope itself.
    Have you tried setting up the session information on the SOAP envelope's headers?

    Look into the WSDL contract in the bindings section and check if the 'operation' you are calling requires as input an headers message.
    You will need to get the header names from the wsdl contract or API documentation if available.

    On SOAP::WSDL's documentation there is information on how to set up the headers:
    #first define your headers @header = (SOAP::Header->name("FirstHeader")->value("FirstValue"), SOAP::Header->name("SecontHeader")->value("SecondValue")); #and then do the call. please note the backslash my $som=$soap->call( 'method' , name => 'value' , name => 'value' , "soap_headers" => \@header);
      i did try to specify techname and password operation inside soap call header
      but that didnt help, i am still getting err message saying that my SOAP call
      is not authorized, and also when i do just regular call, to authenticate
      i dont see any kind of cookie being returned... maybe i am lookng at the wrong place?
      SOAP::Transport::new: () SOAP::Serializer::new: () SOAP::Deserializer::new: () SOAP::Parser::new: () SOAP::Lite::new: () SOAP::Deserializer::new: () SOAP::Parser::new: () SOAP::Schema::new: () SOAP::Transport::HTTP::Client::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Lite::call: () SOAP::Serializer::envelope: () SOAP::Serializer::envelope: SOAP::Data=HASH(0xa1e032c) SOAP::Data=HASH +(0xa1e9e48) SOAP::Data=HASH(0xa1eef24) SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0xa1c2 +5e0) SOAP::Transport::HTTP::Client::send_receive: POST https://api.com/API/ +API.dll?Handler=Default HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap Content-Length: 573 Content-Type: text/xml; charset=utf-8 SOAPAction: "https://api.com/API/#SessionLoginTechnician" <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http:/ +/www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xm +lsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema +" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmln +s:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><Sessio +nLoginTechnician xmlns="https://api.com/API/"><TechName xsi:type="xsd +:string">user</TechName><Password xsi:type="xsd:string">password</Pas +sword></SessionLoginTechnician></soap:Body></soap:Envelope> SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0xa2a +0b1c) SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK Date: Wed, 19 Dec 2007 20:50:01 GMT Server: Microsoft-IIS/6.0 Content-Length: 469 Content-Type: text/xml Client-Date: Wed, 19 Dec 2007 20:50:01 GMT Client-Peer: 216.229.150.65:443 Client-Response-Num: 1 Client-SSL-Cert-Issuer: /O=VeriSign Trust Network/OU=VeriSign, Inc./OU +=VeriSign International Server CA - Class 3/OU=www.verisign.com/CPS I +ncorp.by Ref. LIABILITY LTD.(c)97 VeriSign Client-SSL-Cert-Subject: /C=US/ST=Massachusetts/L=Framingham/O=Iron Mo +untain, Inc./OU=Icompany name here/OU=Terms of use at www.verisign.co +m/rpa (c)00/CN=blah.com Client-SSL-Cipher: RC4-MD5 Client-SSL-Warning: Peer certificate not verified Set-Cookie: SESSIONID=8kEALmmE+SwBiamHFzGL8xpYyjkW7y3Sl8XOdxXZD/bc34nL +NfeRtVDsyRCP/QqmQq1M; path=/;version=1 X-Powered-By: ASP.NET <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" +xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http +://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.o +rg/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmls +oap.org/soap/encoding/"><snp:SessionLoginTechnician xmlns:snp="https: +//api.com/API/7.5/"><CommunityID>6040</CommunityID></snp:SessionLogin +Technician></soap:Body></soap:Envelope> SOAP::Deserializer::deserialize: () SOAP::Parser::decode: () SOAP::SOM::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Lite::call: ()