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"
);
Related
Basically, I am trying to connect to a SOAP service with 2 way SSL (HTTP client certificate authentication).
I am using PHP SoapClient for this within Laravel.
This is what I have, and it allows me to connect and returns the expected response. So the method is basically correct and the certificate is fine etc. It's just I am having trouble with what I guess is the 2 way SSL part.
$client = new \SoapClient('localwsdlfile.wsdl', array(
'local_cert' => 'localcert.pem',
'passphrase' => 'passphrase',
// 'location' => 'https://wsmurl/login/' // Uncomment to login
));
$response = $client->Get(array(
"AccessKey" => "accesskey",
"ProductID" => "SOMEPRODUCT",
"Scope" => "SOMESCOPE",
"Parameters" => array('Param' => array('_' => 'DATATOLOOKUP', 'id'=>'MOREDATATOLOOKUP'))
));
print_r($response);
The only problem is (obviously because I'm doing something wrong), is I need to add the line 'location' => 'https://wsmurl/login/' the first time I try to connect, otherwise I get an error "SoapFault Login Required"
I then remove the line 'location' => 'https://wsmurl/login/', otherwise, I get an error "SoapFault looks like we got no XML document".
The service provider has a 600 second timeout, where I don't have to "login" again for upto 600 seconds.
After removing this line 'location' => 'https://wsmurl/login/', then it works as expected. Obviously, I can't manually add and remove this line, and I guess I am not doing this correctly.
Can someone tell me a better way to do this please?
Thanks,
Because the location for the login and localwsdlfile.wsdl is different, I could not do it with one call. So we created a function using curl to login and if login is successful it will proceed to the soapclient. Thanks to Brian from freelancer for his assistance here.
$client = new SoapClient('wsdl/VocusSchemas/localwsdlfile.wsdl', array(
'trace' => 1,
'exception' => true
));
try {
$response = $client->Get(array(
// "AccessKey" => "MADAITABNSAATOT1",
"AccessKey" => "accesskey",
"ProductID" => "SOMEPRODUCT",
"Scope" => "SOMESCOPE",
"Parameters" => array('Param' => array('_' => 'DATATOLOOKUP', 'id' => 'MOREDATATOLOOKUP'))
));
Im trying to make this fixed, but im stuck. Im not very skilled with WSDL, SOAP and making an XML with it. I'll keep getting this error "Operation '' is not defined in the WSDL for this service" Did anyone know how did i get rid of this error? My goal is to get an XML with all the occasions from a car garage and put them in my database.
This is my code:
ini_set('soap.wsdl_cache_enabled', 1);
$options = array(
'soap_version' => SOAP_1_2,
'trace' => true,
'exceptions' => true,
'encoding' => 'UTF-8',
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'cache_wsdl' => WSDL_CACHE_DISK,
'login' => '****', // <- username here, i got the right one
'password' => '****' // <- same
);
try{
$client = new SoapClient('https://eigenwebsite.doorlinkenvoorraad.nl/v1/leads/deliver.html?wsdl', $options);
//var_dump($client->__getFunctions());
//echo '<br>';
$klant = array(
"key"=>"****", // got the right one
"klantnummer"=>"****", // got the right one
"lead"=>"information_request",
"testmode"=>"dummy"
);
$quote = $client->deliverLead($klant);
}catch(SoapFault $exception){
echo $exception->getMessage();
}
Try changing the SOAP version to 1.1:
'soap_version' => SOAP_1_1,
The web service only supports SOAP 1.1 from the looks of the WSDL, so it is throwing an error when you send it a SOAP 1.2 message.
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.
Currently i'm trying to build a little PHP - Soap Connector, which worked pretty good so far. But when i'm deploying my little script to my server, it won't work anymore and i have no clue, why.
I'm connecting in 2 different ways (by curling the SOAP WSDL Scheme, and saving it temporary in the script location, and creating from that a new SOAP Client, and creating a SOAP Client directly by using the SOAP WSDL Scheme URL):
$opts = array(
'http'=>array(
'user_agent' => 'PHP Soap Client'
)
);
$context = stream_context_create($opts);
// SOAP 1.2 client
$params = array (
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_2,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 30,
);
$curlStuff = curl_init($soapURL);
curl_setopt($curlStuff,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curlStuff,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curlStuff,CURLOPT_TIMEOUT,30);
$response = curl_exec($curlStuff);
$info = curl_getinfo($curlStuff);
if($response) {
file_put_contents("./tempSoapScheme.wsdl", $response);
}
$soapClient = new SoapClient(
'./tempSoapScheme.wsdl',
array(
'trace' => 1,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
$soapClientTwo = new SoapClient(
$soapURL,
array(
'trace' => 1,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
$result = $soapClient->myLoginMethod(
array(
'username' => 'my#email.example',
'password' => 'password'
)
);
As i said earlier - on my local machine it works like a charm, and everything is fine. The param "soapURL", which is not inside the script, is just the https path to my SOAP WSDL Scheme.
I've tried different options inside "$params" array, other curl setopt settings, but i can't make it work.
The response from both SoapClients:
SOAP-ERROR: Parsing WSDL: Couldn't load from '<MyURL>' : failed to load external entity "<MyURL>", which is pretty uncommon, because the CURL could save everything.
Do you have any suggestions for me?
EDIT - forgot the most important thing:
- The server, which should execute the script, has very strong firewall restrictions, and the SOAP URL Scheme is on another server (not the same). And i guess, that is the point, why it won't work, but i receive an answer from the Scheme by executing CURL.. So it's just SOAP?
i have a problem with running methods with SOAP. I'm using Apache and PHP.
this is the PHP code:
$opts = array(
'ssl' => array('ciphers'=>'RC4-SHA')
);
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$client = new SoapClient('https://host?wsdl', array (
'stream_context' => stream_context_create($opts),
"trace" => 1,
"exceptions" => 0,
"connection_timeout"=>2000));
var_dump($client->__getFunctions());
$params = array ("key" => "value");
$result = $client->availabeFunction($params);
var_dump($result);
The __getFunctions() It returns me all of the available functions.
Then when i'm trying to call the the available function with parameters.
It returns me a strage error message:
public 'faultstring' => string 'Could not connect to host' (length=25)
public 'faultcode' => string 'HTTP' (length=4)
So i presume it is for some reasons are connecting to through the HTTP, but not through HTTPS.
I've looked up the web, and in some cases they are using a local_cert value with a .pem file.
It it neccecity to have it? Or i'm missing something else?
It's an openssl library bug.
At first try to disable SSL check by adding this params
"stream_context" => stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
)
)
)
And next try to not use ?wsdl in location link, try use something like
.wsdl
The solution was much easier as i thoguht it will be:
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$location = 'https://host';
$client = new SoapClient($location . '?wsdl', array (
"trace" => 1,
"exceptions" => 0,
"connection_timeout"=>2000,
"location"=>$location // <- this was the reqiured parameter
));
Everything else is same as before.
This beeing cause by WSDL file configuration, that instead of https URL, it has http.