I'm getting Wrong Version While Sending a SOAP Request - php

I'm working on a flight booking API. I'm sending the data to the server in following way:
$location_URL = "http://59.162.33.102/ArzooWS/services/DOMFlightBooking?wsdl";
$action_URL ="http://booking.flight.arzoo.com";
$client = new SoapClient('http://59.162.33.102/ArzooWS/services/DOMFlightBooking?wsdl', array(
'soap_version' => SOAP_1_1,
'location' => $location_URL,
'uri' => $action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
));
I've also mentioned XML SOAP Body below edited parsed XML Formatted Request:
<?xml version="1.0" encoding="utf-8"?>
<Bookingrequest>
<onwardFlights>
<OriginDestinationOption>
<FareDetails>
<ChargeableFares>
<ActualBaseFare>5060</ActualBaseFare>
<Tax>4380</Tax>
<STax>32</STax>
<SCharge>0</SCharge>
<TDiscount>0</TDiscount>
<TPartnerCommission>0</TPartnerCommission>
</ChargeableFares>
<NonchargeableFares>
<TCharge>0</TCharge>
<TMarkup>300</TMarkup>
<TSdiscount>0</TSdiscount>
</NonchargeableFares>
</FareDetails>
<FlightSegments>
<FlightSegment>
<AirEquipType>321</AirEquipType>
<ArrivalAirportCode>DEL</ArrivalAirportCode>
<ArrivalDateTime>2013-10-20T08:00:00</ArrivalDateTime>
<DepartureAirportCode>BOM</DepartureAirportCode>
<DepartureDateTime>2013-10-20T06:00:00</DepartureDateTime>
<FlightNumber>6019</FlightNumber>
<OperatingAirlineCode>AI</OperatingAirlineCode>
<OperatingAirlineFlightNumber>6019</OperatingAirlineFlightNumber>
<RPH>
</RPH>
<StopQuantity>0</StopQuantity>
<airLineName>Air India</airLineName>
<airportTax>4380</airportTax>
<imageFileName>http://live.arzoo.com/FlightWS/image/AirIndia.gif</imageFileName>
<viaFlight>
</viaFlight>
<BookingClass>
<Availability>4</Availability>
<ResBookDesigCode>U</ResBookDesigCode>
</BookingClass>
<BookingClassFare>
<adultFare>5060</adultFare>
<bookingclass>U</bookingclass>
<classType>Economy</classType>
<farebasiscode>fjyS3YyUlEusLfJ4bwgPvQ==</farebasiscode>
<Rule>This fare is Refundable <br> Baggage : 25K<br>Booking Class : U|Re-Schedule Charges: Rs. 750 per sector + Fare difference (If any) +admin fee 500 + Service Fee of Rs. 250
Sector .|Cancellation Charges : Basic fare +Airline administration fee 500 + Service Charges 250 Per Passenger Per Sector .
|</Rule>
<adultCommission>0</adultCommission>
<childCommission>0</childCommission>
<commissionOnTCharge>0</commissionOnTCharge>
</BookingClassFare>
<Discount>0</Discount>
<airportTaxChild>0</airportTaxChild>
<airportTaxInfant>0</airportTaxInfant>
<adultTaxBreakup>2950,147,1283</adultTaxBreakup>
<childTaxBreakup>0,0,0</childTaxBreakup>
<infantTaxBreakup>0,0,0</infantTaxBreakup>
<octax>0</octax>
</FlightSegment>
</FlightSegments>
<id>arzoo11</id>
<key>wtZcSVMY/gphWFSOTFWg8nkII1434EZIGjnpJNQzayEK8sDjVS91GicTJzH+TWN+pNURIyTJYKOW
O8yH8+0tzpA4t8aEEvzaOE6ZnTtBotFDwLtSiN0xXiTOGgS0siJI1l7d9ata/3rxTgfh9d8ZSmFY
VI5MVaDyd5WrIWHlQL5zqWDbQb1E1IoDSY1wep73c6lg20G9RNQQnpVlWM7U0ZY7zIfz7S3O4J6m
G25LJItzqWDbQb1E1IoDSY1wep73c6lg20G9RNSKA0mNcHqe93OpYNtBvUTUpvdITjbFOR52+H1V
tJqs5kJfo6Sh44vDThgZv6ARhgviIKxphH+kbb9fDhZYRaCPm3lupCgitSmWO8yH8+0tzolfF9kG
WM+AaZ58PxEZgqCbbbGbXj1Z0D7dHS59eVX1JxMnMf5NY37ZbJ5llqmBpycTJzH+TWN+2WyeZZap
gacnEycx/k1jftlsnmWWqYGnJxMnMf5NY37ZbJ5llqmBpycTJzH+TWN+2WyeZZapgacnEycx/k1j
ftlsnmWWqYGnJxMnMf5NY36po4tljIBmEJgePqv2qP9fd/Usd8Uuz7FDwLtSiN0xXvtUK9az69O/
JxMnMf5NY37yK2PFSCI6AM2hLlYrFkYJQ8C7UojdMV7NoS5WKxZGCcr5VjCR04wgRviI6n9DzL3N
oS5WKxZGCUPAu1KI3TFezaEuVisWRglDwLtSiN0xXv4Xbn4sigRMv18OFlhFoI/cKcKe7FftvScT
JzH+TWN+2WyeZZapgacnEycx/k1jftlsnmWWqYGnJxMnMf5NY377Oxb/b44TR5Y7zIfz7S3O16CE
sDaAROm13h/OHWeGHw==</key>
</OriginDestinationOption>
</onwardFlights>
<returnFlights>
</returnFlights>
<personName>
<CustomerInfo>
<givenName>Rajnish</givenName>
<surName>Dubey</surName>
<nameReference>Mr.</nameReference>
<psgrtype>adt</psgrtype>
</CustomerInfo>
</personName>
<telePhone>
<phoneNumber>9595959595</phoneNumber>
</telePhone>
<email>
<emailAddress>rajnishdubey1988#gmail.com</emailAddress>
</email>
<creditcardno>5266474530046446</creditcardno>
<Clientid>7232326</Clientid>
<Clientpassword>*AB424E52FBBHDSFS74DFFSA7B747A9BAF61F8E</Clientpassword>
<partnerRefId>100200</partnerRefId>
<Clienttype>ArzooFWS1.1</Clienttype>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
</Bookingrequest>
try
{
//$result = $client->getAvailability($dom->saveXML($request));
$result = $client->getBookingDetails($dom->saveXML($request));
$response= htmlentities($result);
echo "<h1> Client Response: </h1><pre>".htmlspecialchars($result, ENT_QUOTES)."</pre>";
}
catch(Exception $e){
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
Now when the data is being sent to the server I get an exception 'Wrong version'. I checked on the SERVER side, the log for this particular client isn't being hit at all. Means that the server didn't received the request. The same WSDL request format is created by AVAILABILITY API of the flight. I'm getting the available flight list by AVAILABILITY API. I converted the above code in XML, the API documentation has the same format as i'm sending the request. I checked on the internet but didn't find the solution for the same. Some says the version of SOAP i'm using is different but that's not the case. Because the Flight and Hotel Availability API Has same method of request and receiving the data from server.
Please help me. I'm stuck on this. Your help will be Appreciated.

this is working code of flight availibility by arzoo..
i also getting error while using SOAP CLIENT but when i use nusoap then they give me result..using this code if u get error like ip/password mismatch then You will call arzoo to verify your clientid and clientpassword
<?php
ini_set('max_execution_time','180');
include 'lib/nusoap.php';
$location_URL ='http://avail.flight.arzoo.com';
$action_URL ='http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl';
$Request = '<Request>
<Origin>BOM</Origin>
<Destination>DEL</Destination>
<DepartDate>2017-02-02</DepartDate>
<ReturnDate>2017-02-02</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<Clientid>Given by Arzoo.com</Clientid>
<Clientpassword>Given by Arzoo.com</Clientpassword>
<Clienttype>ArzooFWS1.1</Clienttype>
<Preferredclass>E</Preferredclass>
<mode>ONE</mode>
<PreferredAirline>AI</PreferredAirline>
</Request>';
$clientinfo = array('soap_version'=>SOAP_1_1,
'location' =>$location_URL,
'uri' =>$action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
);
$client = new nusoap_client('http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl', $clientinfo);
//print_r($client);
$result = $client->call('getAvailability', array($Request));
echo"<pre>";
print_r($result);
$clientInfo =simplexml_load_string(utf8_encode($result));
$flight = $clientInfo->Response__Depart->OriginDestinationOptions->OriginDestinationOption;
$error =$clientInfo->error__tag;
//echo $error;
var_dump($flight);
//exit;
//echo"<pre>";
//print_r($result);
//ECHO $error;
?>

Related

Problem with sending array via Soap WSDL - PHP

I have problem with send SOAP query. For some reason my code [numerNadania] isn't good. I guess it's some problem with structure.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:e=http://e-nadawca.poczta-polska.pl
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<e:addReklamacje>
<reklamowanaPrzesylka
dataNadania="2018-05-22"
urzadNadania="260578"
powodReklamacjiOpis="TEST TEST TEST"
odszkodowanie="0" oplata="0" oczekiwaneOdszkodowanie="0">
<przesylka
guid="262A34BA2C1111116237B659B312F5EB"
numerNadania="00159007738099827991"
opis="TEST"
planowanaDataNadania="2018-05-22"
xsi:type="e:przesylkaBiznesowaType"/>
<powodReklamacji
idPowodGlowny="4"
powodGlownyOpis="TEST TEST TEST">
<powodSzczegolowy
idPowodSzczegolowy="9" powodSzczegolowyOpis="TEST TEST TEST"/>
</powodReklamacji>
</reklamowanaPrzesylka>
</e:addReklamacje>
</soapenv:Body>
</soapev:Envelope>
$options["login"] = "***";
$options["password"] = "***";
$options["soap_version"] = SOAP_1_2;
$wsdl = 'en.wsdl';
try {
$client = new SoapClient($wsdl,$options);
}
catch(Throwable $e) {
echo 'Wystąpił problem z połączniem API';
}
$params = array(
'reklamowanaPrzesylka' => array (
'przesylka' => array (
'guid' => getGuid(),
'numerNadania' => $id,
),
'powodReklamacji' => "Czas dostawy",
)
);
$problem = $client->addReklamacje($params);
stdClass Object ( [errorNumber] => 13250 [errorDesc] => Numer nadania dla składanych reklamacji jest wymagany [guid] => F8CF816CDF4DD8151116C0EE340C4031 )
Numer nadania dla składanych reklamacji jest wymagany - Send number is required [TRANSLATE]
In the past i have been using wsdl2php converters to create client code that resolves most of this type of issues.
See this one for example: https://github.com/rquadling/wsdl2php
They all work pretty much the same, you need to provide ?wsdl endpoint, run script and it will produce client code and output it in to file. Than you can include file and use generated classes and methods.
Hope this helps.

SOAP header in PHP

I have a complex SOAP header which fails to pass security on the web service:
Here is the required XML:
<soapenv:Header>
<sec:Customer>
<sec:Name>Name</sec:Name>
</sec:Customer>
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken>
<Username>User</Username>
<Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</Password>
</UsernameToken>
</Security>
</soapenv:Header>';
And here is the PHP I tried:
$client = new SoapClient($wsdl, array( 'trace' => 1,'exceptions' => 1));
$cust = array('Name' => "Name");
$token = array('UsernameToken' => array('Username' => "User",'Password' => "Password" ));
$headers = array();
$headers[] = new SoapHeader($ns1,'Customer',$cust);
$headers[] = new SoapHeader($ns2,'Security',$token);
$client->__setSoapHeaders($headers);
WsSecutiry headers are specials and can be tricky to set. They are not declared as the other common Soap Headers.
Your WsSecurity header is pretty basic whereas it can be more complexe when it includes password digest, nonce, and other timestamp information. WsSecurity header can easily be added using the WsSecurity project.
You have to be sure of what is sent (SoapClient::__getLastRequest()) and you mus tbe sure that it matches what is expected if you don't want an error in return. If you still have an error, you should first contact the web service provider.

Quick license manager webservice doesn't accept request

I want to use the Quick License Manager SOAP webservice to connect an e-commerce wordpress plugin to enable the user to buy a license and show it after a successful purchase.So for now, I'm trying to call the function GetProductInfo to get the info of an existing product I created with the QLM Management Console.I use the SoapClient php class but when I try to make a request I get this response :
Error validating request: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. . Caller: GetProductInfo
I don't understand what's wrong with my request, so I need help...
Here is the code I use :
<?php
$url = "https://quicklicensemanager.com/****/qlm/qlmservice.asmx";
$wsdl = $url . "?WSDL";
$soapClient = new SoapClient($wsdl, array(
"encoding" => "utf8",
"trace" => TRUE,
"version" => SOAP_1_1
));
$req = sprintf(
'<?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>
<QlmSoapHeader xmlns="http://www.interactive-studios.net/qlmweb">
<CultureName>%s</CultureName>
<UtcOffset>%d</UtcOffset>
</QlmSoapHeader>
</soap:Header>
<soap:Body>
<GetProductInfo xmlns="http://www.interactive-studios.net/qlmweb">
<eProductName>%s</eProductName>
<productID>%d</productID>
<major>%d</major>
<minor>%d</minor>
</GetProductInfo>
</soap:Body>
</soap:Envelope>', "en_US", 0, "The IO plug-in: Student License", 4, 1, 0);
echo '<pre>';
print_r(htmlentities($req));
echo '</pre>';
$action = "http://www.interactive-studios.net/qlmweb/GetProductInfo";
$res = $soapClient->__doRequest($req, $url, $action, 1);
echo '<pre>';
print_r($res);
echo '</pre>';
echo "=======================================================";
echo '<pre>';
print_r(htmlentities($soapClient->__getLastRequest()));
echo '</pre>';
echo "=======================================================";
echo '<pre>';
print_r($soapClient->__getLastRequestHeaders());
echo '</pre>';
Thanks in advance for your help.
EDIT
Now I tried to change the field productID and it appears that it is the one that was wrong. So it needs to be a base64 string, so I updated my code :
</soap:Envelope>', "en_US", 0, "The IO plug-in: Student License", 4, 1, 0); becomes </soap:Envelope>', "en_US", 0, base64_encode("The IO plug-in: Student License"), 4, 1, 0);
The new error message is :
Error validating request: Length of the data to decrypt is invalid.. Caller: GetProductInfo
After hours of searching, I found this in the documentation, at page 121 :
Note that all the methods exposed by the web service cannot be called with a URL except GetActivationKey
and ActivateKey. All other web methods implement a secure authentication mechanism that only accepts
requests from the QLM Console.
So, as I was trying to call GetProductInfo, it couldn't work outside the QLM Console.

DHL Tracking Api and PHP

I'm currently working on a project, where i have to get the status of a packet (sent with DHL). I read about the DHL API, which return an XML, but somehow there are no good examples out there. I have found some code snippets, but i have no clue where to register for API Key's.
Have anyone some links or examples for me?
Best regards,
Lukas
There is also this PHP client that can be used to consume the DHL XML API. It can handle all the different services exposed by DHL.
https://github.com/alfallouji/DHL-API
This client does not rely or depend on any framework and it should be fairly easy to integrate with your own code. You can check the samples folder for example on how to use it.
https://github.com/jklz/DHL-API-Tracking-PHP
It is used to connect into DHL using the XML-PI to track shipments using the Air Way Bill. it can handle a single tracking number or as many as you feed into it (has been tested with 250 and other then taking a little time to run had no problems). automatically takes and breaks the array of tracking numbers into chunks and then sends the request to DHL making sure not to pass the max number that can be tracked per request then returns the results as a array.
Quick and dirty without any third party lib and using official API:
<?php
$mode = 'sandbox'; // sandbox or production
$username = ''; // dhl developer account name, not email
$password = ''; // dhl developer account pass
$appname = 'zt12345'; // sandbox app
$apppass = 'geheim'; // sandbox app
$endpoint = 'https://cig.dhl.de/services/' . $mode . '/rest/sendungsverfolgung';
$payload = simplexml_load_string( '<?xml version="1.0" encoding="UTF-8" standalone="no"?><data appname="' . $appname . '" language-code="de" password="' . $apppass . '" piece-code="" request="d-get-piece-detail"/>' );
$shipmentids = array(
'00340434161094015902' // in sandbox only special numbers are allowed
);
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Authorization: Basic " . base64_encode( "$username:$password" )
)
);
$context = stream_context_create( $opts );
foreach ( $shipmentids as $shipmentid ) {
$payload->attributes()->{'piece-code'} = $shipmentid;
$response = file_get_contents( $endpoint . '?' . http_build_query( array( 'xml' => $payload->saveXML() ) ), false, $context );
$responseXml = simplexml_load_string( $response );
$status = null;
// get last state
foreach ( $responseXml->data->data->data as $event ) {
$status = $event->attributes()->{'event-short-status'};
}
echo "Shipment " . $shipmentid . " is in state: " . $status . "\n";
}
There is a nice blog about this. It is unfortunately in German, but the code that is displayed there should still make sense to you.
Source: https://blog.simlau.net/dhl-tracking-api-php.html
Excerpt:
function dhl_tracking($trackingnumber)
{
$data = '<?xml version="1.0" encoding="ISO-8859-1" ?>';
$data .= '<data appname="nol-public" password="anfang" request="get-status-for-public-user" language-code="de">';
$data .= ' <data piece-code="'.$trackingnumber.'"></data>';
$data .= '</data>';
// URL bauen und File hohlen
$xml = simplexml_load_file(sprintf(
'http://nolp.dhl.de/nextt-online-public/direct/nexttjlibpublicservlet?xml=%s', $data
));
// FALSE, wenn Syntax oder HTTP Error
if ($xml === false) return false;
// Wandelt das SimpleXML Objekt in ein Array um
foreach ($xml->data->data->attributes() as $key => $value) {
$return[$key] = (string) $value;
}
return $return;
}
// Aufruf der Funktion
print_r(dhl_tracking($tracking_number));
This function will give back an array that will contain some tracking information:
Array
(
[status] => Die Sendung wurde erfolgreich zugestellt.
[recipient-id-text] => Nachbar
[product-name] => DHL PAKET
[pan-recipient-name] => SIMON LAUGER
)
(In fact, there is WAY more data in there.)
I hope this will help you in some way.

PHP Soap - Could not connect to host

I have looked at other solutions for this but can't find a similar issue:
This bit of code works ok:
$wsdlUrl = "https://pilot.prove-uru.co.uk/URUws/uru10a.asmx?wsdl";
$client = new soapclient($wsdlUrl);
print_r($client->__getFunctions());
However when I try to make a method call:
$params = array("AddressLookupUK" => array("address" => array("Postcode" => "NE20 9RF"),
'AccountName' => "xxxx",
'Password' => "xxxx"));
$result = $client->AddressLookupUK($params);
I get the error message "SoapFault exception: [HTTP] Could not connect to host". If I change the method call to
$result = $client->FalseMethod($params);
I get back "Function ("FalseMethod") is not a valid method for this service" which shows it is connecting as expected. Does anybody have any pointers I can try?
Thanks
Here is the code I used, hope it helps someone:
$wsdlUrl = "address.wsdl";
$client = new soapclient($wsdlUrl);
$params = array('address' => array('Postcode' => $postcode, 'BuildingNo' => $buildingNo),
'AccountName' => 'XXXX',
'Password' => 'XXXX');
$result = $client->AddressLookupUK($params);
$echoText = '';
if (is_null($result->AddressLookupUKResult))
{
//tell the user nothing was returned
}
else
{
//checks to see if the result set contains only one item
if (is_array($result->AddressLookupUKResult->URUAddressFixed))
{
foreach($result->AddressLookupUKResult->URUAddressFixed as $item)
{
//use code like $item->BuildingNo to access the data
}
}
else
{
//if there was there was more than one then access using something like
$result->AddressLookupUKResult->URUAddressFixed->BuildingNo
}
}
Richard
At the WSDL you see the endpoint deinition:
<wsdl:service name="URU10a">
<wsdl:port name="URU10aSoap" binding="tns:URU10aSoap">
<soap:address location="https://pilot.prove-uru.co.uk:8443/URUws/uru10a.asmx"/>
</wsdl:port>
<wsdl:port name="URU10aSoap12" binding="tns:URU10aSoap12">
<soap12:address location="https://pilot.prove-uru.co.uk:8443/URUws/uru10a.asmx"/>
</wsdl:port>
</wsdl:service>
I think, you have problems connecting the 8443 port. In my restricted network, the service works neither.
EDIT
Ok, I tried to connect using the standard SSL port by changing the WSDL. I have saved the WSDL from https://pilot.prove-uru.co.uk/URUws/uru10a.asmx?wsdl to my hard drive, removed the port numbers from the endpoint definitions and tried to connect using soapUI. Hooray, I got a response.
So maybe they moved the service from 8443 to 443 w/o updating the WSDL. Or it runs under both ports but you (and me) cannot connect the 8443 because of limitations of our local networks. Anyway I think you should contact the provider of this service and clarify this point instead of using a patched version of their WSDL.
The "Function ("FalseMethod") is not a valid method for this service" error is only due to the WSDL check. PHP successfully downloaded the WSDL, but can't access the Webservices in it.
You have to debug the Soap Call with trace set to 1:
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
echo "REQUEST HEADERS:\n" . $client->__getLastRequestHeaders() . "\n";
echo "RESPONSE HEADERS:\n" . $client->__getLastResponseHeaders() . "\n";
echo "Response:\n" . $client->__getLastResponse() . "\n";
Also, have a look at the URL's sets in the Wsdl.
I accepted DerVO's answer as his pointers helped me resolve the issue. The port number was not totally causing the issue but I feel may have been contributing to it in some way.
When loading the WSDL in soap UI it was displaying the simple and complex object types without issue, but within PHP this caused it to fall over i.e. the WSDL defined a set of "
Richard

Categories