SOAP-ERROR: Encoding: object has no 'FinalBookingDate' property - php

Before starting, I know, this errors means that I should have defined the property FinalBookingDate, but just keep reading and you will understand my point of view.
The url is: http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?op=getBookingList
I was testing first with SoapUi, and I successfull get the list that I need:
And on php, I only can get this response:
The SoapClient from php is:
$params = array('soap_version' => SOAP_1_2, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding'=>'UTF-8', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new \SoapClient('http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?wsdl', $params);
And then, the code to retrieve the data:
/*
$query = array(
'InitialServiceDate' => '2015-01-20',
'InitialBookingDate' => '2015-01-20',
'FinalBookingDate' => '2015-01-20',
'FinalServiceDate' => '2015-01-20',
'CreationUserId' => 1338,
'CityId' => 4166,
'ServiceTypes' => array('eServiceType' => 'HOTEL')
);
*/
$query = array(
'InitialBookingDate' => '2015-01-20',
'ServiceTypes' => array('eServiceType' => 'HOTEL')
);
$args = new \stdClass;
$args->credential = new \stdClass;
$args->credential->UserName = $conn['userPass']['usr'];
$args->credential->Password = $conn['userPass']['pass'];
$args->searchBookingCriteria = new \stdClass;
$args->searchBookingCriteria->InitialBookingDate = '2015-01-20';
$args->searchBookingCriteria->ServiceTypes = new \stdClass;
$args->searchBookingCriteria->ServiceTypes->eServiceType = 'HOTEL';
//$args = array('credential'=>$credentials, 'searchBookingCriteria' => $query);
$data = $conn['client']->getBookingList($args);
print_r($data);
exit;
As you can see, I tried 2 ways to send the $args to getBookingList, as far I know both of then is valid and yet both of then (with array or object) return the same error. On the code commented at first you can see that I tried to define all does properties that the web service asks but after defining all of then I get a empty result.
My question is, there is some extra param to define on SoapClient that I should do? Why the SoapUI can do it with success? What I have missing here?
Bonus: A print of SoapUI full screen with the default request including the optional params https://www.evernote.com/shard/s14/sh/fb5ac276-8147-4e09-95bb-afa0be66d7a6/d273441c74186bf1e600b42ab3303899/deep/0/SoapUI-5.0.0.png

Can you try this more direct approach:
try {
$params = array('soap_version' => SOAP_1_2, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding'=>'UTF-8', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new SoapClient('http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?wsdl',$params);
} catch (SoapFault $E) {
echo $E->faultstring;
}
if ($client) {
$req_params = array('credential' =>
array('userName' => 'XXXXXXX',
'Password' => 'XXXXXXX'),
'searchBookingCriteria' =>
array('BookingNumber' => array('int' => 'XXXXXXXXX'),
'ServiceTypes' => array('eServiceType' => 'HOTEL'),
'PassengerName'=> 'XXXXXXXX',
'InitialBookingDate'=> '2015-01-16',
'FinalBookingDate'=> '2015-01-16',
'InitialServiceDate' => '2015-01-18',
'FinalServiceDate' => '2015-01-18',
'BookingStatus'=> array('eStatus' => 'ACTIVATED'),
'PaymentStatus'=> array('ePaymentStatus' => 'Payed'),
'CreationUserId'=> 'XXX',
'CityId'=> 'XXXX',
'ExternalReference'=> '')
);
$response = $client->__soapCall('getBookingList',array($req_params));
var_dump($response);
}

Try (and add) this approach:
$args->searchBookingCriteria->FinalBookingDate = '2015-01-22';
$args->searchBookingCriteria->InitialServiceDate = '2015-01-22';
$args->searchBookingCriteria->FinalServiceDate = '2015-01-22';
$args->searchBookingCriteria->CreationUserId = 'abc';
$args->searchBookingCriteria->CityId = 'abc';

Related

How can I use SoapClient in my Php Programm

How can I use the SoapClient with the method "sites_web_domain_add" to interact with the ispconfig api? My Code produces a folowing error:
error
Also soap client/server is set to enabled.
If i execute the code in my terminal it just works fine but not in my controller, so have I missed something? Like importing the right soap?
Thanks for helping!
$username = 'apiuser';
$password = '1234';
$soap_location = 'https://localhost:8080/remote/index.php';
$soap_uri = 'https://localhost:8080/remote/';
$context = stream_context_create(
[
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
]
);
$client = new SoapClient(
null,
[
'location' => $soap_location,
'uri' => $soap_uri,
'trace' => 1,
'exceptions' => 1,
'stream_context' => $context
]
);
try {
if ($session_id = $client->login($username, $password)) {
echo "Login successful. Session ID: $session_id<br>";
}
//* Set the function parameters.
$client_id = 1;
$params = [
'server_id' => 1,
'ip_address' => '*',
'domain' => 'test2.int',
'type' => 'vhost', // vhost | alias | vhostalias | subdomain | vhostsubdomain
];
$client->sites_web_domain_add($session_id, $client_id, $params, $readonly = false);
if ($client->logout($session_id)) {
echo "Logged out.<br>";
}
} catch (SoapFault $e) {
echo $client->__getLastResponse();
die("SOAP Error: {$e->getMessage()}");
}

PHP SoapClient Cannot process the message because the content type 'text/xml;

I cannot connect to webservice and send/receive data
Error
HTTP,Cannot process the message because the content type 'text/xml;
charset=utf-8' was not the expected type 'application/soap+xml;
charset=utf-8'.
Code
$parameters = [
'UserName' => 12324,
'Password' => 432123,
'Bill_Id' => 153585611140,
'Payment_Id' => 8560103,
];
$url="https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";
$method = "VerifyBillPaymentWithAddData";
$client = new SoapClient($url);
try{
$info = $client->__call($method, array($parameters));
}catch (SoapFault $fault){
die($fault->faultcode.','.$fault->faultstring);
}
Notice : not work Soap version 1,1 and other resolve sample for this error in stackoverflow.
You could try
$url = "https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";
try {
$client = new SoapClient($url, [
"soap_version" => SOAP_1_2, // SOAP_1_1
'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
'trace' => 1,
'exception' => 1,
'keep_alive' => false,
'connection_timeout' => 500000
]);
print_r($client->__getFunctions());
} catch (SOAPFault $f) {
error_log('ERROR => '.$f);
}
to verify that your method name is correct.
There you can see the method
VerifyBillPaymentWithAddDataResponse VerifyBillPaymentWithAddData(VerifyBillPaymentWithAddData $parameters)
Next is to check the Type VerifyBillPaymentWithAddData and if the parameter can be an array.
Also you could test to call the method via
$client->VerifyBillPaymentWithAddData([
'UserName' => 12324,
'Password' => 432123,
'Bill_Id' => 153585611140,
'Payment_Id' => 8560103,
]);
or yours except the additional array
$info = $client->__call($method, $parameters);
EDIT:
Assuming to https://stackoverflow.com/a/5409465/1152471 the error could be on the server side, because the server sends an header back that is not compatible with SOAP 1.2 standard.
Maybe you have to use an third party library or even simple sockets to get it working.
Just use the following function. Have fun!
function WebServices($function, $parameters){
$username = '***';
$password = '***';
$url = "http://*.*.*.*/*/*/*WebService.svc?wsdl";
$service_url = 'http://*.*.*.*/*/*/*WebService.svc';
$client = new SoapClient($url, [
"soap_version" => SOAP_1_2,
"UserName"=>$username,
"Password"=>$password,
"SOAPAction"=>"http://tempuri.org/I*WebService/$function",
'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
'trace' => 1,
'exception' => 1,
'keep_alive' => false,
'connection_timeout' => 500000
]);
$action = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', "http://tempuri.org/I*WebService/$function");
$to = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', $service_url);
$client->__setSoapHeaders([$action, $to]);
try{
return $client->__call($function, $parameters);
} catch(SoapFault $e){
return $e->getMessage();
}
}

PHP SOAP WSDL - Could not connect to host

there is a problem trying to execute some functions from the WSDL I have. I connected to the WSDL using Basic Auth, I can see all the functions available with:$functions = $client->__getFunctions();
But then I try to execute any of them I get "[HTTP] Could not connect to host" error. My code here:
ini_set('default_socket_timeout', 150);
header('Content-Type: text/plain');
ini_set("soap.wsdl_cache_enabled", "0");
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
);
// SOAP 1.2 client
$params = array (
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_2,
'trace' => 1, 'exceptions' => 1,
"connection_timeout" => 180,
'stream_context' => stream_context_create($opts),
'login' => 'login',
'password' => 'password',
'cache_wsdl' => WSDL_CACHE_NONE
);
$url = "http://address/webservice/wsdl";
try {
$client = new SoapClient($url, $params);
$functions = $client->__getFunctions();
var_dump($functions);
$response = $client->__soapCall('function_name', array());
$client->function_name();
var_dump($response);
} catch (SoapFault $fault) {
echo '<br>'.$fault;
}
Any ideas? Now in the WSDL file I have a targetNamespace parameter which is "targetNamespace="http://192.168.0.253:85/webservice/soap"" can this be a legit WSDL file? I mean can the namespace be a localhost ip address? Maybe this needs to be fixed in the WSDL side?
Found the solution. What was missing:
'location' => "http://address/webservice/soap",
In parameters.

How can i specify which service use on a WSDL?

I have to consume a WSDL that haves 2 Services (Service1 & Service2) and this ones has many functions.
What i need is: make a soap_call to the functionX on the Service1 and functionY on the Service2.
This is how actually i make the connection:
$options = [
"cache_wsdl" => WSDL_CACHE_NONE,
"soap_version" => SOAP_1_1,
"connection_timeout" => 120,
"trace" => 1,
"exceptions" => 1,
];
$this->_objSoap = new SoapClient($this->_sURLService,$options);
Execute a function:
$result = (array)$this->_objSoap->__soapCall('functionX', $params);
Just invoke them?
$this->_objSoap = new SoapClient($this->_sURLService,$options);
$result_1 = $objSoap->function_x();
$result_2 = $objSoap->function_y();
I was making the call with Soap_Call, and that was the problem :/, now i make it on the obj.
Connection:
$options = [
"cache_wsdl" => WSDL_CACHE_NONE,
"soap_version" => SOAP_1_1,
"connection_timeout" => 120,
"trace" => 1,
"exceptions" => 1,
];
$this->_objSoap = new SoapClient($this->_sURLService,$options);
Before
$result = (array)$this->_objSoap->Soap_Call(functionX,$params));
Now
$result = (array)$this->_objSoap->FunctionX($params);
The problem now is that i don't understand why using Soap_Call works on my others WSDL :/.

SOAP Client error list array read

When I try to read from a function returning a list array or map array I have an error, can anyone help me? This is my code:
<?php
$serverAddress = "YOUR_SERVER_IP";
$serviceUrl = "http://127.0.0.1/soap-live/";
$wsdlUrl = $serviceUrl . 'wsdl/';
$clientParams = array(
'login' => 'admin',
'password' => 'paris',
'location' => $serviceUrl,
'trace' => true,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
);
$client = new SoapClient($wsdlUrl, $clientParams);
echo "===== Get_api_version( ) =====<br/>\n";
$response = $client->Get_input_info(1);
echo $response->return . "<br/>\n";
?>
Best Regards.

Categories