0

We have been given the below xml and need to translate into Perl.

POST /carrierintegrationapi.asmx HTTP/1.1
Host: carrierintegrationapi.3tlogistics.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://carrierintegrationapi.3tlogistics.net/Login"

<?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:Header>
    <CiSoapHeader xmlns="https://carrierintegrationapi.3tlogistics.net/">
      <Username>cccict</Username>
      <Password>xxxxxx</Password>
      <AuthenticationToken>string</AuthenticationToken>
    </CiSoapHeader>
    </soap:Header>
  <soap:Body>
   <Login xmlns="https://carrierintegrationapi.3tlogistics.net/" />
  </soap:Body>
 </soap:Envelope>';

Our attempt:

my $service = SOAP::Lite
            -> service    ('https://carrierintegrationapi.3tlogistics.net/carrierintegrationapi.asmx');

 my $AuthHeader = SOAP::Header->new(
  name =>'AuthenticationHeader',
  attr => { xmlns => "https://carrierintegrationapi.3tlogistics.net/" },
  value => {Username => 'cccict', Password => 'xxxxxx' },
);
my $result = $service->GetIt($AuthHeader);

We get mismatched tag in parser.pm?

Tom
  • 16,842
  • 17
  • 45
  • 54
cccict
  • 1
  • @Ehsan Please don't add "Thanks for your time :D" to questions. It's unnecessary noise and doesn't belong in posts. Also, please don't use inline code formatting for things that aren't code, like "xml" (which should be "XML" anyway). – ThisSuitIsBlackNot Jun 28 '16 at 19:50

1 Answers1

0

Since there is no answer so far, I'm goingo to show you an alternative. You can submit the request as raw post. SOAPAction might be declared in the header. Compiling the correct SOAP with SOAP::Lite is time intensive and nested elements are hard to read. The example does also support non-blocking calling style out of the box with a small modification.

use Mojo::UserAgent;
use strict;
use warnings;

# User-Agent 
my $ua = Mojo::UserAgent->new;

my $username = 'Username';
my $password = 'Password';
my $authtoken = 'Token';

my $message = <<"SOAP_REQUEST";
<?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:Header>
    <CiSoapHeader xmlns="https://carrierintegrationapi.3tlogistics.net/">
      <Username>$username</Username>
      <Password>$password</Password>
      <AuthenticationToken>$authtoken</AuthenticationToken>
    </CiSoapHeader>
    </soap:Header>
  <soap:Body>
  <Login xmlns="https://carrierintegrationapi.3tlogistics.net/" />
  </soap:Body>
</soap:Envelope>
SOAP_REQUEST

my $tx = $ua->post('https://carrierintegrationapi.3tlogistics.net/carrierintegrationapi.asm' => { 'Hello' => "I'm a Header" } => $message);
print $tx->res->body;
user3606329
  • 2,405
  • 1
  • 16
  • 28
  • Hi, thank you for your help. It is giving a syntax error at this line. my $ua = Mojo::UserAgent -> new; – cccict Jun 29 '16 at 08:17
  • You have to install Mojo::UserAgent through CPAN. Type in your shell "cpan install Mojo::UserAgent". – user3606329 Jun 29 '16 at 09:04