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.
Related
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?
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.
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"
);
Can anyone tell me a reason the following code shouldn't work, assuming it points to the right external files and calls the correct functions?
<?php
$xmlstr = simplexml_load_file("file.xml");
$wsdl = 'file.wsdl';
$client = new SoapClient($wsdl, array(
'cache_wsdl' => WSDL_CACHE_NONE,
'cache_ttl' => 86400,
'trace' => true,
'exceptions' => true,
));
$xmlVar = new SoapVar($xmlstr, XSD_ANYXML);
$client->DoFunction($xmlstr);
The xml file it points to is an exact output of what i should send the server to get a response but all I get is an error 'Fatal error: Uncaught SoapFault exception' talking about the header can't be null. Which sounds like it isn't getting the authentication details but they are all correct. Is there anything I'm obviously doing wrong here?