SOAP api not accepting keys - php

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!

Related

SoapFault: looks like we got no XML document Magento and laravel

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!!!

php soap client issue

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)

Savon header authentication problems

I am trying to authenticate a site. I found an example for PHP, but I'm having some trouble rewriting it to Ruby.
Example code:
class HRDConfig {
public $uid = "myuid";
public $pass = "mypassword123";
const NS = "https://www.tested.site.com/partnerAPI/";
const PARTNER = "https://www.tested.site.com/partnerAPI/Partner.php?wsdl";
}
ini_set("soap.wsdl_cache_enabled", "1");
$soap = new SoapClient(HRDConfig::PARTNER, array("encoding"=>"UTF-8", "exceptions" => true));
$soap->__setSoapHeaders(array(new SoapHeader(HRDConfig::NS, "AuthHeader", new HRDConfig())));
My code:
client = Savon.client(
wsdl: 'https://www.tested.site.com/partnerAPI/Partner.php?wsdl',
soap_header:{
'AuthHeader' => {'uid'=>'myuid','pass'=>'mypass'}
})
What I'm doing wrong?
$client = new SoapClient(
'http://service.example.com?wsdl',
array('soap_version' => '1.2',
'connect_timeout' => 10,
'compression' => (SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP),
'cache_wdsl' => WSDL_CACHE_NONE));
$header = new SoapHeader(
'http://service.example.com?wsdl',
'AuthenticateRequest',
new SoapVar(array('apiKey' => '***api******'), SOAP_ENC_OBJECT),
true);
$client->__setSoapHeaders($header);
try {
echo("\n[SOAP response]\n");
$response = $client->__soapCall('your function', array());
echo("\n[After response]\n");
echo("\n{$response }\n");
}
catch (Exception $e) {
echo($e->getMessage());
}
Note: here "apiKey" is my params to authenticate api, your can be different

PHP Parse SOAP envelope to XML

I been at this all day and feel like I'm getting nowhere, I need to get this to display as an xml like how it is on this page http://admin.stock.imdfulfilment.com/api/service.asmx/GetCouriers. Yet the following code
<?
try
{
$soap_url = 'http://admin.stock.imdfulfilment.com/api/service.asmx?wsdl';
$client = new SoapClient($soap_url, array(
'trace' => 1,
'exceptions'=>true,
'GetCouriersResult' => 'xml')
);
$client->GetCouriers();
$xml = simplexml_load_string($client->__getLastResponse());
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->registerXPathNamespace('xsd', 'http://www.w3.org/2001/XMLSchema');
foreach($xml->xpath('//soap:Envelope') as $item) {
echo "$item\n\n";
}
}
catch (Exception $e)
{
print_r($e);
}
?>
It returns doubly encoded XML, I have no idea why someone thought that a Good Idea (perhaps someone who doesn't want to bother with updating their wsdl):
$soap_url = 'http://admin.stock.imdfulfilment.com/api/service.asmx?wsdl';
$client = new SoapClient($soap_url, array(
'trace' => 1,
'exceptions'=>true,
'GetCouriersResult' => 'xml')
);
$result = $client->GetCouriers();
echo $result->GetCouriersResult->any;
//or you can load it in DOM or simpleXML if you need to read it;
$the_response_should_have_been = new simpleXMLElement($result->GetCouriersResult->any);

PHP SOAP issue feeding in results

I'm trying to create a page that displays current results from CA Lottery using PHP. I've used XML before, but am having issues with SOAP. I found this page, but its not a lot of help.
I've put together the code below, and was able to get it to return an object. But I can't get it to feed in the results I need. Any help would be amazing.
try {
$options = array(
'soap_version'=>SOAP_1_1,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient('http://services.calottery.com/CALotteryService.asmx?WSDL', $options);
} catch (Exception $e) {
echo "<p>Exception Error!</p>";
echo $e->getMessage();
}
echo '<p>Connection: Success;</p>';
try {
$response = $client->GetCurrentGameInfo();
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
$x = simplexml_load_string("<?xml version=\"1.0\"?>".$response->GetCurrentGameInfoResult->any);
var_dump($x);
Try this
var_dump($response);
$x = simplexml_load_string("<?xml version=\"1.0\"?>".$response->GetCurrentGameInfoResult->any);
var_dump($x);
at the end of your script. Kind of odd, but calottery is returning a fragment of XML in the response that needs to be further processed ( the simplexml_load_string ).

Categories