Data at the root level is invalid php SoapClient - php

I have to create a SOAP header like:
<?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>
<AuthHeader xmlns="URL">
<Username>string</Username>
<Password>string</Password>
<PublicKey>string</PublicKey>
<NewPassword>string</NewPassword>
<UserType>string</UserType>
</AuthHeader>
</soap:Header>
<soap:Body>
<getClients xmlns="URL" />
</soap:Body>
</soap:Envelope>
Connect with WS With sesion(), it returns nothing, but when the XML contains something, I get that error.
This is my code:
$wsdl= "URL?wsdl';
$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
try {
$soap = new SoapClient($wsdl, $options);
$valor = $soap->getPublicKey();
}
catch(Exception $e) {
die($e->getMessage());
}
$key=$valor->getPublicKeyResult->any;
$endpoint = 'url';
$user;
$password;
$password64 = mb_convert_encoding($password,'UCS-2LE','auto');
$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$rsa->loadKey($key);
$rsa->setPublicKey($key);
$ciphertext = $rsa->encrypt($password64);
$cipher64 = base64_encode($ciphertext);
$headerbody = array(
'PublicKey'=>$rsa->getPublicKey(),
'Username'=>$user,
'Password'=>$cipher64,
'NewPassword'=>'',
'UserType'=>'U'
);
$header = new SOAPHeader($endpoint, 'AuthHeader', $headerbody);
$soap->__setSoapHeaders($header);
try {
$data = $soap->sesion();
$data = $soap->getClients();
}
catch(Exception $e) {
die($e->getMessage());
}
var_dump($soap->__getTypes());
echo "REQUEST:\n" . htmlentities($soap->__getLastRequest()) . "\n";
echo "RESPONSE:\n" . htmlentities($soap->__getLastResponse()) . "\n";
var_dump($data);
die;
And the header that form:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="URL">
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:Username>$user</ns1:Username>
<ns1:Password>$password</ns1:Password>
<ns1:PublicKey>-----BEGIN PUBLIC KEY-----
 PUBLIC KEY#13; -----END PUBLIC KEY-----</ns1:PublicKey>
<ns1:NewPassword></ns1:NewPassword>
<ns1:UserType>U</ns1:UserType>
</ns1:AuthHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getClients/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I have tried various solutions proposed and none of them work, I'm not able to include in the envelope the xlms:xsi, xlms:xsd. And I think that is what I need.

Related

How do I access XML Data

I am using PHP to connect to a SOAP API using GuzzleHttp.
Code
$client = new Client();
$headers = [
'Host' => 'server',
'Content-Type' => 'application/soap+xml; charset=utf-8',
'SOAPAction' => 'action'
];
$body = '<?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>
<GetInventoryStatus xmlns="action">
<Credentials>
<Username></Username>
<Password></Password>
</Credentials>
<MaterialCode>' . $_GET['matcode'] . '</MaterialCode>
</GetInventoryStatus>
</soap12:Body>
</soap12:Envelope>';
$request = new Request('POST', 'web service here', $headers, $body);
$res = $client->sendAsync($request)->wait();
$xml1 = ($res->getBody());
After running the API, I get the result back in text but upon viewing the source code the below XML is getting returned back
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetInventoryStatusResponse
xmlns="http://localhost/EnterpriseWebService/Enterprise Connect">
<GetInventoryStatusResult>
<MaterialCode>10029</MaterialCode>
<MaterialDescription>12 PT TANGO C2S</MaterialDescription>
<QuantityOnHand>138000.00</QuantityOnHand>
<QuantityAllocated>20400.00</QuantityAllocated>
<QuantityAvailable>117600.00</QuantityAvailable>
<QuantityOnOrder>0.00</QuantityOnOrder>
<QuantityInProduction>0.00</QuantityInProduction>
<ReorderQuantity>0.00</ReorderQuantity>
<ReorderLevel>0.00</ReorderLevel>
<DesiredLevel>0.00</DesiredLevel>
</GetInventoryStatusResult>
</GetInventoryStatusResponse>
</soap:Body>
</soap:Envelope>
If I echo the $xml1, I get everything in text format.
How do I access the variables through the XML?
You need to parse it. I have used DOMDocument but one could use other techniques.
<?php
$str = '<' . '?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetInventoryStatusResponse
xmlns="http://localhost/EnterpriseWebService/EnterpriseConnect">
<GetInventoryStatusResult>
<MaterialCode>10029</MaterialCode>
<MaterialDescription>12 PT TANGO C2S</MaterialDescription>
<QuantityOnHand>138000.00</QuantityOnHand>
<QuantityAllocated>20400.00</QuantityAllocated>
<QuantityAvailable>117600.00</QuantityAvailable>
<QuantityOnOrder>0.00</QuantityOnOrder>
<QuantityInProduction>0.00</QuantityInProduction>
<ReorderQuantity>0.00</ReorderQuantity>
<ReorderLevel>0.00</ReorderLevel>
<DesiredLevel>0.00</DesiredLevel>
</GetInventoryStatusResult>
</GetInventoryStatusResponse>
</soap:Body>
</soap:Envelope>';
// $xml = simplexml_load_string($str);
$xml = new DOMDocument();
$xml->loadXML($str);
$xpath = new DOMXpath($xml);
$nodes = $xpath->query('//*');
$names = array();
foreach ($nodes as $node)
{
$names[] = [
'name' => $node->nodeName,
'value' => $node->textContent,
];
}
print_r($names);

how can i create a soap in php for SABRE?

I am new to the world of SOAP, I want to know how I can make a request to the saber servers, but I have not succeeded, I need help to make the following request.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Header>
<eb:MessageHeader SOAP-ENV:mustUnderstand="1" eb:version="1.0">
<eb:From>
<eb:PartyId>Client</eb:PartyId>
</eb:From>
<eb:To>
<eb:PartyId>SWS</eb:PartyId>
</eb:To>
<eb:CPAId>3DBJ</eb:CPAId>
<eb:ConversationId>MyConversationID</eb:ConversationId>
<eb:Service>Service</eb:Service>
<eb:Action>getReservationRQ</eb:Action>
<eb:MessageData>
<eb:MessageId></eb:MessageId>
<eb:Timestamp></eb:Timestamp>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
<wsse:BinarySecurityToken>Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/RESE!ICESMSLB\/RES.LB!1</wsse:BinarySecurityToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns7:GetReservationRQ xmlns:ns7="http://webservices.sabre.com/pnrbuilder/v1_15" Version="1.15.0">
<ns7:Locator>JXJ</ns7:Locator>
<ns7:RequestType>Stateful</ns7:RequestType>
<ns7:ReturnOptions UnmaskCreditCard="true">
<ns7:SubjectAreas>
<ns7:SubjectArea>PRICING_INFORMATION</ns7:SubjectArea>
</ns7:SubjectAreas>
</ns7:ReturnOptions>
</ns7:GetReservationRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is my XML that I sent in postman and it generates a result but when I do it in PHP it generates an error.
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://webservices.havail.sabre.com' : Document is empty
$client = new SoapClient("https://webservices.havail.sabre.com");
$checkVatParameters =array(
'BinarySecurityToken' => 'Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/RESE!ICESMSLB\/RES.LB!',
'Locator' => 'JXJ',
'RequestType'=>'Stateful',
'SubjectArea'=>'PRICING_INFORMATION'
);//variables
$result=$client->__getFunctions();
$result = $client->GetReservationRQ($checkVatParameters);
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
}
they only gave me a URL but it asks me WDSL
It looks like the SoapClient is wanting the URL for the WSDL itself, not the service endpoint. For GetReservationRQ, you can find this at http://files.developer.sabre.com/wsdl/sabreXML1.0.00/pnrservices/GetReservation_1.19.0.wsdl.
he solved my problem in this way
$location_URL = "https://sws-crt.cert.havail.sabre.com";
$action_URL = "http://webservices.sabre.com/pnrbuilder/v1_15";
$client = new SoapClient(null, array(
'location' => $location_URL,
'uri' => "",
'trace' => 1,
));
$order_return = $client->__doRequest($xml,$location_URL,$action_URL,1);
I made a modification and works perfectly for PHP SOAP.
function leerreservas($pnr) {
error_reporting(0);
//ini_set('display_errors', true);
//ini_set('display_startup_errors', true);
$oDate = new DateTime();
$timestamp = $oDate->format('Y-m-d\Th:i:sP');
$timetolive = $oDate->add(new DateInterval('PT1H'))->format('Y-m-d\Th:i:sP');
$Locator=$pnr;
$BinarySecurityToken=selectokken(); $endpoint=selecendpoint();
$sabre=sabredatosusuario();
$namespaces="http://webservices.sabre.com/pnrbuilder/v1_15";
$test = '<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:eb="http://www.ebxml.org/namespaces/messageHeader"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Header>
<eb:MessageHeader SOAP-ENV:mustUnderstand="1" eb:version="1.0">
<eb:From>
<eb:PartyId>Client</eb:PartyId>
</eb:From>
<eb:To>
<eb:PartyId>SWS</eb:PartyId>
</eb:To>
<eb:CPAId>'.$sabre['ipcc'].'</eb:CPAId>
<eb:ConversationId>MyConversationID</eb:ConversationId>
<eb:Service>Service</eb:Service>
<eb:Action>getReservationRQ</eb:Action>
<eb:MessageData>
<eb:MessageId>'.$timestamp.'</eb:MessageId>
<eb:Timestamp>'.$timetolive.'</eb:Timestamp>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
<wsse:BinarySecurityToken>'.$BinarySecurityToken.'</wsse:BinarySecurityToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns7:GetReservationRQ xmlns:ns7="'.$namespaces.'" Version="1.15.0">
<ns7:Locator>'.$Locator.'</ns7:Locator>
<ns7:RequestType>Stateful</ns7:RequestType>
<ns7:ReturnOptions UnmaskCreditCard="true">
<ns7:SubjectAreas>
<ns7:SubjectArea>PRICING_INFORMATION</ns7:SubjectArea>
</ns7:SubjectAreas>
</ns7:ReturnOptions>
</ns7:GetReservationRQ>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
$location_URL = $endpoint;
$action_URL = $namespaces;
$client = new SoapClient(null, array( 'location' => $location_URL, 'uri' => "",
'trace' => 1, ));
try {
$order_return = $client->__doRequest($test,$location_URL,$action_URL,1);
//Get response from here
if (empty($order_return)) {
echo "vacio";
} else {
$xml2 = reemplazo($order_return);
$xml = simplexml_load_string($xml2, 'SimpleXMLElement', LIBXML_NOCDATA);
$datos = json_decode(json_encode($xml), TRUE);
echo print_r($datos);
}
} catch (SoapFault $exception) {
var_dump(get_class($exception));
var_dump($exception);
}
}

SOAP with literal xml in php

How do i create this specific xml output by SOAP using SoapHeader and __setSoapHeaders? I can't do the same XML like i want. i don't want this ns1 and ns2 in envelope tag, and in header i need this Action SOAP-ENV:mustUnderstand="1" ...
This is my code:
try{
$client = new SoapClient('https://thesite.com.br/wcf/SvcContratos.svc?wsdl', array('trace' => 1,'use' => SOAP_LITERAL));
$usuario='user_1';
$senha='1234';
$tipo='1';
$header = new SoapHeader("http://schemas.microsoft.com/ws/2005/05/addressing/none","Action", "http://tempuri.org/ISvcContratos/GerarToken");
$client->__setSoapHeaders($header);
$params = new SoapVar("<objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><d4p1:DsSenha>".$senha."</d4p1:DsSenha><d4p1:DsUsuario>".$usuario."</d4p1:DsUsuario><d4p1:IdTipoConsulta>".$tipo."</d4p1:IdTipoConsulta></objLogin>", XSD_ANYXML);
$data = $client->GerarToken($params);
echo $client->__getLastRequest();
}catch(SoapFault $fault){
echo $client->__getLastRequest()."<br>".$fault->getMessage();
}
With this php code i had this wrong XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://schemas.microsoft.com/ws/2005/05/addressing/none">
<SOAP-ENV:Header>
<ns2:Action>http://tempuri.org/ISvcContratos/GerarToken</ns2:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<GerarToken>
<objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<d4p1:DsSenha>1234</d4p1:DsSenha>
<d4p1:DsUsuario>user_1</d4p1:DsUsuario>
<d4p1:IdTipoConsulta>1</d4p1:IdTipoConsulta>
</objLogin>
</GerarToken>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I need to send this XML by soap:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ISvcContratos/GerarToken</Action>
</s:Header>
<s:Body>
<GerarToken xmlns="http://tempuri.org/">
<objLogin xmlns:d4p1="http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<d4p1:DsSenha>1234</d4p1:DsSenha>
<d4p1:DsUsuario>USER_1</d4p1:DsUsuario>
<d4p1:IdTipoConsulta>1</d4p1:IdTipoConsulta>
</objLogin>
</GerarToken>
</s:Body>
</s:Envelope>
well, finally I got an affirmative answer from the server, which opens the doors for me now to try to consume the wsdl follows below the code that I used to solve the problem:
try{
$client = new SoapClient('https://thesite.com.br/wcf/SvcContratos.svc?wsdl', array('trace' => 1,'use' => SOAP_LITERAL, 'style' => SOAP_DOCUMENT,));
$usuario='user_1';
$senha='1234';
$params = new SoapVar("<GerarToken xmlns='http://tempuri.org/'><objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><d4p1:DsUsuario>".$usuario."</d4p1:DsUsuario><d4p1:DsSenha>".$senha."</d4p1:DsSenha><d4p1:IdTipoConsulta>Data</d4p1:IdTipoConsulta></objLogin></GerarToken>", XSD_ANYXML);
$data = $client->GerarToken($params);
$xml = json_decode(json_encode($data),true);
print_r($xml);
echo $client->__getLastRequest();
}catch(SoapFault $fault){
echo $client->__getLastRequest()."<br>".$fault->getMessage();
}

Php soapClient array method

Im new to php soapclient. I have been trying to send details and i keep getting an empty response.
I have this soap details
<?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>
<UploadFileNew_XML xmlns="http://tempuri.org/GAPS_Uploader/FileUploader">
<xmlRequest>
<transdetails>
<transactions>
<transaction>
<amount>25000</amount>
<paymentdate>2017/09/07</paymentdate>
<reference>777777</reference>
<remarks>Name</remarks>
<vendorcode>vendor details</vendorcode>
<vendorname>Vendor name</vendorname>
<vendoracctnumber>0212893398</vendoracctnumber>
<vendorbankcode>058152052</vendorbankcode>
</transaction>
</transactions>>
</transdetails>
<customerid>481472280</customerid>
<username>username</username>
<password>password</password>
<hash>'.hash(sha512,'hasdetails','other details').'</hash>
</xmlRequest>
</UploadFileNew_XML>
</soap:Body>
</soap:Envelope>
<?php
try{
define ('WSDL_URL_BAL','http://gtweb.gtbank.com/gaps_fileuploader/fileuploader.asmx?WSDL');
$stringsample = [];
$stringsample['transdetails']['transactions']['transaction']['amount'] = 2500;
$stringsample['transdetails']['transactions']['transaction']['paymentdate'] = '2017/09/07';
$stringsample['transdetails']['transactions']['transaction']['reference'] = 'aaaaaa';
$stringsample['transdetails']['transactions']['transaction']['remarks'] = 'bbbbbbb';
$stringsample['transdetails']['transactions']['transaction']['vendorcode'] = 'cccccccc';
$stringsample['transdetails']['transactions']['transaction']['vendorname'] = 'ddddddd';
$stringsample['transdetails']['transactions']['transaction']['vendoracctnumber'] = '0212893398';
$stringsample['transdetails']['transactions']['transaction']['vendorbankcode'] = '058152052';
$stringsample['customerid'] = '12345';
$stringsample['customerid'] = 'abcdefrggg';
$stringsample['customerid'] = '445566555';
$stringsample['hash'] = 'hash';
$endpoint = WSDL_URL_BAL;
$client = new SoapClient( $endpoint );
$params = array('xmlrequest'=>$stringsample);
$result = $client->UploadFileNew_XML($params);
$data = $result->UploadFileNew_XMLResult;
echo $data.'<br /><br /><br />';
print_r($data); echo '<br /><br /><br />';
} catch (Exception $e) {
$message = 'Error: '. $e->getMessage();
}
echo $message;
?>
kindly help i could not find useful resource online. Thanks.
I have made modifications to the highlighted comment.
I dont know if i translated the soap correctly into the array i am parsing.
Your code is missing the Whole things it seems like you copied and pasted the source.. So i have just Added the <?php ?> tags to your Code.
<?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>
<UploadFileNew_XML xmlns="http://tempuri.org/GAPS_Uploader/FileUploader">
<xmlRequest>
<transdetails>
<transactions>
<transaction>
<amount>25000</amount>
<paymentdate>2017/09/07</paymentdate>
<reference>777777</reference>
<remarks>Name</remarks>
<vendorcode>vendor details</vendorcode>
<vendorname>Vendor name</vendorname>
<vendoracctnumber>0212893398</vendoracctnumber>
<vendorbankcode>058152052</vendorbankcode>
</transaction>
</transactions>>
</transdetails>
<customerid>481472280</customerid>
<username>username</username>
<password>password</password>
<hash>'.hash(sha512,'hasdetails','other details').'</hash>
</xmlRequest>
</UploadFileNew_XML>
</soap:Body>
</soap:Envelope>
<?php
try{
define ('WSDL_URL_BAL','http://gtweb.gtbank.com/gaps_fileuploader/fileuploader.asmx?WSDL');
$client = new SoapClient( $endpoint );
$params = array('xmlrequest'=>$stringsample);
$result = $client->UploadFileNew_XML($params);
$data = $result->UploadFileNew_XMLResult;
echo $data.'<br /><br /><br />';
print_r($data); echo '<br /><br /><br />';
} catch (Exception $e) {
$message = 'Error: '. $e->getMessage();
}
echo $message;
?>
Now you can try it.

how to create soap xml request in php

<?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>
<SubmitRequest xmlns="http://tripauthority.com/hotel">
<siteID>string</siteID>
<username>string</username>
<password>string</password>
<xmlFormattedString>string</xmlFormattedString>
</SubmitRequest>
</soap:Body>
</soap:Envelope>
we have to call above soap xml. i have siteID, username, password.
where string is below
<ArnRequest><Availability DisplayCurrency="USD" SearchTimeout="15"><HotelAvailability InDate="2007-04-26" OutDate="2007-04-29" Rooms="1" Adults="2" Children="0"><Hotel HotelID="8800"/></HotelAvailability></Availability></ArnRequest>
i have no idea on soap request. Please help with this to get response on above soap xml in PHP. The above xml is of ARN(Alliance reservations)
thanks in advance.
Calling webservices is quite easy, if you just want to send a prepared raw xml request. You could for instance use CURL for this.
Here the code which uses the php soapclient. I get "invalid credentials", but this should be ok as you'd put your valid ones in there.
<?
$string ='<ArnRequest><Availability DisplayCurrency="USD" SearchTimeout="15"><HotelAvailability InDate="2007-04-26" OutDate="2007-04-29" Rooms="1" Adults="2" Children="0"><Hotel HotelID="8800"/></HotelAvailability></Availability></ArnRequest>';
$xmlrequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hot="http://tripauthority.com/hotel">
<soapenv:Header/>
<soapenv:Body>
<hot:SubmitRequestDoc>
<!--Optional:-->
<hot:siteID>string</hot:siteID>
<!--Optional:-->
<hot:aUserName>string</hot:aUserName>
<!--Optional:-->
<hot:aPassword>string</hot:aPassword>
<!--Optional:-->
<hot:aRequestDoc>
'.$string.'
</hot:aRequestDoc>
</hot:SubmitRequestDoc>
</soapenv:Body>
</soapenv:Envelope>';
//Change this variables.
$location_URL = 'http://tripauthority.com/hotel.asmx';
$action_URL = "http://tripauthority.com/hotel/SubmitRequestDoc";
$client = new SoapClient(null, array(
'location' => $location_URL,
'uri' => "http://tripauthority.com/hotel",
'trace' => 1,
));
$order_return = $client->__doRequest($xmlrequest,$location_URL,$action_URL,1);
//Get response from here
print_r($order_return);
?>
I have solve my question if any body in future have any problem they this code works for him, please check-
<?php
error_reporting(E_ALL);
define('API_SITEID', $your_siteid);
define('API_USERNAME', $your_uname);
define('API_PASSWORD', $your_pass);
define('API_WSDL', 'http://tripauthority.com/hotel.asmx?WSDL');
ini_set("soap.wsdl_cache_enabled", "0");
$xmlReq = '<ArnRequest>
<Availability DisplayCurrency="USD" SearchTimeout="15">
<HotelAvailability InDate="2014-09-26" OutDate="2014-09-27" Rooms="1" Adults="1" Children="0">
<Hotel HotelID="8800"/>
</HotelAvailability>
</Availability>
</ArnRequest>';
echo '<form action="" method="post">
<strong>XML Request:</strong>
<p>
<textarea style="width:100%;height:400px;" id="xmlReq" name="xmlReq">'.$xmlReq.'</textarea>
</p>
<input type="submit" name="submit" id="submit" value="Test Request">
<input type="hidden" name="avail" id="avail" value="y">
</form>';
if($_POST['avail'] == "y") {
$xmlRes = doSoapRequest((($_POST['xmlReq']) ? $_POST['xmlReq'] : $xmlReq));
echo '<strong>XML Response:</strong>
<p>
<textarea style="width:100%;height:400px;" id="xmlRes" name="xmlRes">'.$xmlRes.'</textarea>
</p>';
}
function doSoapRequest($xmlReq) {
try {
$client = new SoapClient(API_WSDL);
return $client->SubmitRequestRpc(API_SITEID, API_USERNAME, API_PASSWORD, $xmlReq);
} catch(SoapFault $exception) {
return "Fault Code: {$exception->getMessage()}";
}
}
?>
Thanks
php has a built in Soap Client as of 5: http://php.net/manual/en/class.soapclient.php
$wsdl = '
<?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>
<SubmitRequest xmlns="http://tripauthority.com/hotel">
<siteID>string</siteID>
<username>string</username>
<password>string</password>
<xmlFormattedString>string</xmlFormattedString>
</SubmitRequest>
</soap:Body>
</soap:Envelope>
';
try {
$client = #new SOAPClient($wsdl); // or preferably, use a url for $wsdl
// Be sure to replace soapMethodToUse with a mouthed for this specific web service.
$response = $client->soapMethodToUse(array('key' => 'val')); // Any params for this method
} catch (Exception $e) {
echo $e->getMessage();
}
die(var_dump($response));
You may try to modify request with help of __doRequest function.
<?php
require_once("MySoapClient.php");
$client = new MySoapClient($wsdUrl,array(
'location' => "http://tripauthority.com/hotel",
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
$parameters=array('siteID'=>'string','username'=>'string','password'=>'string');
$err=0;
try{
$info = $client->__soapCall("SubmitRequest",array($parameters));
}
catch (SoapFault $e) {
echo "<pre>faultcode: '".$e->faultcode."'</pre>";
echo "<pre>faultstring: '".$e->getMessage()."'</pre>";
$err=1;
}
if($err==0)
print_r($info);
else
echo $client->__getLastRequest();
?>
MySoapClient.php
<?php
class MySoapClient extends SoapClient
{
function __doRequest($request, $location, $action, $version, $one_way = 0) {
$request=str_replace('</SubmitRequest>','<xmlFormattedString>string</xmlFormattedString></SubmitRequest>',$request);
return $request;
}
}
?>

Categories