How can i specify which service use on a WSDL? - php

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 :/.

Related

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.

Object of class stdClass could not be converted to string for SOAP request

When I run the following script, I get an "Object of class stdClass could not be converted to string for SOAP request" error on the $client->LatLonListZipCode($args) line and I can't figure out why. Any ideas?
<?php
$contextOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
),
'http' => array(
'timeout' => 5 //seconds
)
);
//create stream context
$stream_context = stream_context_create($contextOptions);
//create client instance (over HTTPS)
$client = new SoapClient('http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl', array(
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => 1,
'trace' => 1,
'stream_context' => $stream_context,
'soap_version'=> SOAP_1_2,
'connection_timeout' => 5 //seconds
));//SoapClient
$args = new stdClass();
$args->zipCodeList = '10001';
$z = $client->LatLonListZipCode($args);
Exception cause
First of all - this service is using SOAP 1.1 not SOAP 1.2. Change your $client specification to:
$client = new SoapClient('http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl', array(
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => 1,
'trace' => 1,
'stream_context' => $stream_context,
'soap_version'=> SOAP_1_1,//<-- note change here
'connection_timeout' => 5 //seconds
));//SoapClient
Service Definition
As it is stated in your WSDL service specification, you can find that LatLonListZipCode function is defined as:
<operation name="LatLonListZipCode">
<documentation>Returns a list of latitude and longitude pairs with each pair corresponding to an input zip code.</documentation>
<input message="tns:LatLonListZipCodeRequest"/>
<output message="tns:LatLonListZipCodeResponse"/>
</operation>
and expected parameters are defined as:
<xsd:simpleType name="zipCodeListType">
<xsd:restriction base='xsd:string'>
<xsd:pattern value="\d{5}(\-\d{4})?( \d{5}(\-\d{4})?)*" />
</xsd:restriction>
</xsd:simpleType>
Proper call
So we know, that server demands only one string parameter named zipCodeList. Now we can deduct that your code should be like this:
$args = array("zipCodeList"=>'10001');
try {
$z = $client->LatLonListZipCode($args);
} catch (SoapFault $e) {
echo $e->faultcode;
}
Note that i'm catching SoapFault exception. It will help you to understand server-side errors. Read more about it in PHP documentation.

PHP SOAP Could not connect to host on function execution

I'm trying to achieve a PHP SOAP client to a HTTPS service and am encountering a problem I'm not able to resolve. Am I missing something ?
I'm establishing a connection to the webservice as follow :
$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true
)
));
$opt = array(
"login" => self::LOGIN,
"password" => self::PASSWORD,
"authentication" => SOAP_AUTHENTICATION_BASIC,
"trace" => true,
"exceptions" => 1,
"cache_wsdl" => WSDL_CACHE_NONE,
'stream_context' => $context,
"connection_timeout" => 30
);
try {
$soapClient = new SoapClient(self::WS_URL, $opt);
} catch (SoapFault $fault) {
var_dump($fault);
exit;
}
Until there, no problem seems to arise. Then I do the following :
var_dump($soapClient->__getFunctions());
This gives me the list of functions the service can process and I get a valid response :
array(1) { [0]=> string(54) "ListReponseAX getElig(Elig $in0)" }
The problem then arises : when I try to invoke the getElig function, no matter how I try, I get this "Could not connect to host" error.
I've tried passing the data as text, as array, as object, as soapvar but always get this annoying error.
Thx in advance for any help !
Ok the problem is resolved. For those wondering, the WSDL file had an endpoint specification in it that was irrelevant. By forcing the location upon initializing the PHP class, I was able to circumvent the problem :
$opt = array(
"login" => self::LOGIN,
"password" => self::PASSWORD,
"authentication" => SOAP_AUTHENTICATION_BASIC,
"trace" => true,
"exceptions" => 1,
"cache_wsdl" => WSDL_CACHE_NONE,
'stream_context' => $context,
"connection_timeout" => 30,
"location" => "https://the_location_to_force"
);

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

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';

Categories