I have to develop a php client which connects to a soap webservice server.
With SoapUI, I can test the webservice which is working fine.
But from my php client, I get the following error:
syntax error near << from >>
Here is my php client code:
$wsdl = 'http://intrageo.cannes.fr:81/AdresseRecherche/searchByWhereClause?wsdl';
$trace = true;
$exceptions = false;
$xml_array['context'] = '?';
$xml_array['table'] = 'adr_digadr';
$xml_array['colonneARecuperer'] = 'numero';
$xml_array['clauseWere'] = 'nomvoie= \'BOULEVARD COINTET\'';
$xml_array['nbMaxLignes'] = 10;
try {
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->getDistinctValue($xml_array);
} catch (Exception $e) {
echo "Error!";
echo $e->getMessage();
echo 'Last response: '. $client->__getLastResponse();
}
var_dump($response);
Thanks for help.
It works if I use $response=$client->_soapCall("getDistinctValue",$xml_array); instead of $response=$client->getDistinctValue($xml_array)
Related
i am with a problem in my application Laravel, when i use the SoapClient, for example my_object_soap->login(); returned this error:
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML
I already tried several solutions that I researched in google and here, but I did not solve my problem.
my code follows:
ini_set("soap.wsdl_cache_enabled",0);
ini_set("soap.wsdl_cache",0);
ini_set("error_reporting",-1);
ini_set("display_errors","On");
$wsdl_url = "https://example.com/index.php/api/v2_soap/index/?wsdl";
$apiAuth = new \stdClass();
$apiAuth->username = trim("myusermagento");
$apiAuth->apiKey = trim("mykeymagento");
try{
$proxy = new SoapClient($wsdl_url,array('cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true));
$session = $proxy->login($apiAuth);
$data = $session;
$status = true;
$responseStatus = 200;
} catch(SoapFault $e) {
$error = $e->getMessage();
$data = $proxy->__getLastResponse();
$status = false;
$responseStatus = 500;
}
return Response::json([
'success' => $status,
'data' => $data,
'erros'=> $error,
],$responseStatus);
I have no idea which a problem, when i tested in SoapUI, with this user and key, it's alright, but in my app not.
My magento version app is 1.6.2, and my php is 7.2, I already tried to downgrade to php 5.6 because it could be incompatibility with the magento version and my php but it still did not work.
Can someone help me?
Try this one, structure your request as follows
$options = array('trace'=> true,'exceptions' => true);
$client = new \SoapClient('https://www.example.com?wsdl',$options);
$params = new \stdClass();
$params->key1 = 'XXXXXX';
$params->Key2 = 'XXXXX';
$soapVar = new \SoapVar($params,SOAP_ENC_OBJECT);
$header = new \SoapHeader('https://www.example?wsdl','credentials',$soapVar);
$client->__setSoapHeaders(array($header));
$result=$client->login(function parameters here);
Cheers!!!
I'm trying to get data out of a SOAP API (complexType) but it's saying that my provided data is incorrect.
Errormessage I'm getting: "Wrong combination LINKCODE/LINKHASH"
(LINKCODE represents CompanyId & LINKHASH represents linkHash)
The weird thing is though, when I'm trying to get data using http://www.soapclient.com/soaptest.html, it works...
Are there things I have to provide such as schemes or encodings?
Anyway, this is my code:
<?php
include_once 'getArticles.class.php';
$objGetArticles = new getArticles();
$objGetArticles->CompanyId = 'xxx';
$objGetArticles->linkHash = 'xxx';
$objGetArticles->SyncOnlyGlobalPrices = 1;
$wsdl = "https://wcupwebservice.syscom.be/wsWCupDemo/wsWCupDemo.exe/wsdl/IwsWCup";
$client = new SoapClient($wsdl,
array (
'trace' => 1,
'exceptions' => 0,
'cache_wsdl' => WSDL_CACHE_NONE,
'keep_alive' => false
)
);
try {
$result = $client->getArticles(new SoapVar($objGetArticles, SOAP_ENC_OBJECT));
echo "<pre>";
print_r($result);
}catch (SOAPFault $f) {
echo $f->getMessage();
}catch (Exception $e) {
echo $e->getMessage();
}
getArticles.class.php:
<?php
class getArticles{
var $CompanyId;
var $linkHash;
var $SyncOnlyGlobalPrices;
}
Anybody know what to do here? I've spent so much time on this already.. Thanks!
I am using SOAP to call a web servicefrom a Linux Centos 6 server and a php client. In this week I have been getting could not connect to host error from soapCall method. My code is as below and I have not changed it at all for some months but recently it gets this error most of the time. I have read most answers to related questions here but my problem have not been solved.
$wsdl="http://x.x.x.x:x/gw/services/Service?wsdl";
//Set key as HTTP Header
$aHTTP['http']['header'] = "key:" .$key ."\r\n";
$context = stream_context_create($aHTTP);
try
{
$client = new SoapClient($wsdl,array("soap_version" => SOAP_1_2,'trace' => 1,"stream_context" => $context));
}
catch(Exception $e)
{
return "something";
}
//I make $parametrs
try
{
$res = $client->__soapCall("send",array($parametrs));
}
catch(Exception $e)
{
print_r($e->getMessage()); //Most of the time it prints could not connect to host
}
I changed SOAP from _1_1 to _1_2 but nothing changed.
This is how I call SOAP webservice, please note Service?wsdl should be Service.wsdl
Example
//Initialize values
$wsdl = "Service.wsdl";
$url = "http://x.x.x.x:x/gw/services/";
$username = "********"; //add username
$password = "********"; //add password
$client = new SoapClient("$url".$wsdl);
$params = array(
"username"=>$username,
"password"=>$password
);
$response = $client->UserLogIn($params); //UserLogIn is the function name
var_dump($response); // to see webservice response
I tried the below code though I am not sure whether these are the required set of scripts, but it didn't work and gives
SOAP-ERROR: Parsing WSDL: Couldn't load from : Start tag expected, '<' not found
$wsdlUrl = 'http://localhost/magento20_0407/soap/default?wsdl_list=1';
$apiUser = 'testUser';
$apiKey = 'admin123';
$token = 'xioxnuuebn7tlh8ytu7781t14w7ftwmp';
$opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\nConnection: close\r\n"));
$context = stream_context_create($opts);
stream_context_set_option($context, "http", "protocol_version", 1.1);
fpassthru(fopen($wsdlUrl, 'r', false, $context));
$opts = array('http'=>array('header' => 'Authorization: Bearer '.$token));
$serviceArgs = array("id"=>1);
try{
$context = stream_context_create($opts);
$soapClient = new SoapClient($wsdlUrl, array('version' => SOAP_1_2, 'context' => $context));
$soapResponse = $soapClient->customerCustomerAccountServiceV1($serviceArgs);
}catch(Exception $e){
$e->getMessage();
}
var_dump($soapResponse);exit;
Can anyone share the code to make SOAP connection in Magento2.x
In Magento1.x the below code works fine to connect SOAP
$apiUrl = 'http://localhost/magento_28_03/index.php/api/soap?wsdl';
$apiUser = 'testUser';
$apiKey = 'admin123';
ini_set("soap.wsdl_cache_enabled", "0");
try{
$client = new SoapClient($apiUrl, array('cache_wsdl' => WSDL_CACHE_NONE));
} catch (SoapFault $e) {
echo 'Error in Soap Connection : '.$e->getMessage();
}
try {
$session = $client->login($apiUser, $apiKey);
if($session) echo 'SOAP Connection Successful.';
else echo 'SOAP Connection Failed.';
} catch (SoapFault $e) {
echo 'Wrong Soap credentials : '.$e->getMessage();
}
But the above doesn't work for Magento 1. Can anyone say, what changes the above code needs to work fine for Magento 2?
For SOAP API call follow the below
test.php
<?php
$token = 'YOUR_ACCESS_TOKEN';
require('vendor/zendframework/zend-server/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client/Common.php');
$addArgs = array('num1'=>2, 'num2'=>1);// Get Request
$sumArgs = array('nums'=>array(2,1000));// Post request
//$wsdlUrl = YOUR_BASE_URL."soap?wsdl&services=customerAccountManagementV1,customerCustomerRepositoryV1,alanKentCalculatorWebServiceCalculatorV1";//To declar multiple
$wsdlUrl = YOUR_BASE_URL."soap?wsdl&services=alanKentCalculatorWebServiceCalculatorV1";
try{
$opts = ['http' => ['header' => "Authorization: Bearer " . $token]];
$context = stream_context_create($opts);
$soapClient = new \Zend\Soap\Client($wsdlUrl);
$soapClient->setSoapVersion(SOAP_1_2);
$soapClient->setStreamContext($context);
}catch(Exception $e){
echo 'Error1 : '.$e->getMessage();
}
try{
$soapResponse = $soapClient->alanKentCalculatorWebServiceCalculatorV1Add($addArgs);print_r($soapResponse);
$soapResponse = $soapClient->alanKentCalculatorWebServiceCalculatorV1Sum($sumArgs);print_r($soapResponse);
}catch(Exception $e){
echo 'Error2 : '.$e->getMessage();
}
?>
http://YOUR_BASE_URL/test.php
SOAP-ERROR: Parsing WSDL: Couldn't load from : Start tag expected, '<' not found
Tells you all you need to know; the URL you're trying to load isn't a proper WSDL.
What are the contents of: http://localhost/magento20_0407/soap/default?wsdl_list=1
I am tring to access http://xxxxxxxxxxx/CRM2011/XRMServices/2011/Organization.svc?wsdl
I can able to see functions list. means i can access to webservice. But while i tring to write data using function create it through "an error occurred when verifying security for the message" my code is below
<?php
date_default_timezone_set("Asia/Kolkata");
ini_set("soap.wsdl_cache_enabled", "0");
$location = "http://182.18.175.29/CRM2011/XRMServices/2011/Organization.svc?wsdl";
$config['Username'] = 'xxxxxxx';
$config['Password'] = 'xxxxxx';
$config['soap_version'] = SOAP_1_2;
$config['trace'] = 1; // enable trace to view what is happening
$config['use'] = SOAP_LITERAL;
$config['style'] = SOAP_DOCUMENT;
$config['exceptions'] = 0; // disable exceptions
$config["cache_wsdl"] = WSDL_CACHE_NONE; // disable any caching on the wsdl, encase you alter the wsdl server
$config["features"] = SOAP_SINGLE_ELEMENT_ARRAYS;
include_once 'ntlmSoap.php';
$client = new NTLMSoapClient($location, $config);
print('<pre>');
print_r($client->__getFunctions());
$HeaderSecurity = array("UsernameToken" => array("Username" => 'xxxxxx', "Password" => 'xxxxxx'));
$header[] = new SoapHeader($location, "Security", $HeaderSecurity);
$client->__setSoapHeaders($header);
$params = array(
"bmw_firstname" => "test",
"bmw_lastname" => "test"
);
try {
$response = $client->__soapCall("Create", $params);
var_dump($response);
} catch (Exception $e) {
print_r($e);
}
// display what was sent to the server (the request)
echo "<p>Request :" . htmlspecialchars($client->__getLastRequest()) . "</p>";
// display the response from the server
echo "<p>Response:" . htmlspecialchars($client->__getLastResponse()) . "</p>";