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.
Related
I have been spending hours trying to parse a SOAP response that I have no control over. I have tried numerous methods I found on SO with no luck.
Here is the response body I get from edge browser:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:gXMLQueryResponse xmlns:ns1="urn:com-photomask-feconnect-IFeConnect" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:string"><?xml version = '1.0' encoding = 'UTF-8'?>
<ROWSET>
<ROW num="1">
<CUSTOMER_NAME>HITACHI</CUSTOMER_NAME>
</ROW>
</ROWSET>
</return>
</ns1:gXMLQueryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I'm trying to get the CUSTOMER_NAME value.
Here is the code I am using:
$client = new SoapClient($urla, array('trace' => 1));
try {
$result = $client->__soapCall("gXMLQuery", $params);
$response = ($client->__getLastResponse());
$xml = simplexml_load_string($response);
$rows = $xml->children('SOAP-ENV', true)->Body->children('ns1', true)->gXMLQueryResponse->return->ROWSET->ROW;
foreach ($rows as $row)
{
$customer = $row->CUSTOMER_NAME;
echo $customer;
}
} catch (SoapFault $e) {
}
return is a string, you need to parse it first before you can access it using SimpleXML.
First you need to decode the string using html_entity_decode, after that you can load the decoded string with simplexml_load_string:
$return = $xml->children('SOAP-ENV', true)->Body->children('ns1', true)->gXMLQueryResponse->return;
$decodedReturn = html_entity_decode($return, ENT_QUOTES | ENT_XML1, 'UTF-8');
$rowset = simplexml_load_string($decodedReturn);
echo $rowset->ROW->CUSTOMER_NAME;
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.
<?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;
}
}
?>
with php i want to create request , that xml should look like this,
i am using web service test tool and its working fine while i post below xml to it,
i just want to know i can i create soap request exactly like this ?
<?xml version="1.0" encoding="utf-8"?>
<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">
<soap:Header>
<OGHeader transactionID="000032" primaryLangID="E" timeStamp="2008-12-09T09:55:16.3618750-05:00" xmlns="http://webservices.test.com/og/4.3/Core/">
<Origin entityID="OWS" systemType="WEB" />
<Destination entityID="TI" systemType="ORS" />
</OGHeader>
</soap:Header>
<soap:Body>
<AvailabilityRequest xmlns:a="http://webservices.test.com/og/4.3/Availability/" xmlns:hc="http://webservices.test.com/og/4.3/HotelCommon/" summaryOnly="true" xmlns="http://webservices.test.com/ows/5.1/Availability.wsdl">
<a:AvailRequestSegment availReqType="Room" numberOfRooms="1" totalNumberOfGuests="1" totalNumberOfChildren="0">
<a:StayDateRange>
<hc:StartDate>2013-10-05T00:00:00.0000000-05:00</hc:StartDate>
<hc:EndDate>2013-10-06T00:00:00.0000000-05:00</hc:EndDate>
</a:StayDateRange>
<a:HotelSearchCriteria>
<a:Criterion>
<a:HotelRef chainCode="AXA" hotelCode="AXAMUM" />
</a:Criterion>
</a:HotelSearchCriteria>
</a:AvailRequestSegment>
</AvailabilityRequest>
</soap:Body>
</soap:Envelope>
EDIT:
php Code added.
error_reporting(E_ALL);
require_once('../lib/nusoap.php');
$client = new nusoap_client("http://###.###.###.##:8080/ws_ws_51/Availability.asmx?wsdl");
$err = $client->getError();
echo "<pre>";
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}
// Call the SOAP method
$result = $client->call('Availability', array('name' => 'Scott'));
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
this code o/p :
Error
Charset from HTTP Content-Type 'UTF-8' does not match encoding from XML declaration 'iso-8859-1'
I am trying to consume a web service with no success. It looks like the xml is no properly set.
This is my PHP code:
<?php
$wsdlUrl = "http://api.clickatell.com/soap/webservice.php?WSDL";
$serviceUrl = "http://api.clickatell.com/soap/webservice.php";
$request = array("user"=>"anyuser",
"password"=>"asdsda",
"api_id"=>"1234"
);
var_dump($request);
try {
$client = new SoapClient($wsdlUrl, array("trace" => 1, "location" => $serviceUrl));
var_dump($client);
echo "\n";
$response = $client->auth($request);
var_dump($response);
var_dump($client->__getLastRequest());
echo "\n";
}
catch(Exception $exp) {
echo "EXCEPTION";
}
?>
And the SOAP packet is:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.clickatell.com/soap/webservice" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:auth>
<api_id xsi:type="xsd:int">1</api_id>
<user xsi:nil="true"/>
<password xsi:nil="true"/>
</ns1:auth>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
What is wrong with the code that causes that api_id, user and password are not being sent?
If you check out var_dump($client->__getFunctions()), you can see, that the parameters have to be passed like with a normal function call.
So you could do either the verbose thing with SoapParam:
$response = $client->auth(
new SoapParam($request["api_id"], "api_id"),
new SoapParam($request["user"], "user"),
new SoapParam($request["password"], "password")
);
Or less verbose by just giving the parameters directly:
$response = $client->auth($request["api_id"],
$request["user"], $request["password"]);