Why is Soapclient not recognizing my accountInfo object - php

I am trying to create a Soap request to query an automotive vehicle api. Whenever I run the call I get a client error of the following.
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'accountInfo' property in ...
However I have defined it as a property. Relevant lines below:
DEFINE ('API_ENDPOINT',"http://services.chromedata.com/Description/7a?wsdl");
DEFINE ('API_SECRET',"xxx");
DEFINE ('API_ACCTNO',"123456");
DEFINE ('DEBUG',"1");
$useridentification = array('accountInfo' =>array('_'=>"",'number'=>API_ACCTNO, 'secret'=>API_SECRET, 'country'=>'US', 'language'=>'EN', 'behalfof'=>'?'));
enter code here
$vinobject = array('vin'=>$vin);
$buildrequest=array($useridentification, $vinobject);
$client = new SoapClient(API_ENDPOINT);
$response = $client->describeVehicle($buildrequest);
Hopefully this is something obvious to those that work with soap APIs regularly.

Screw SoapClient, using curl. Hope it workks for you.

Related

Uncaught SoapFault exception: [HTTP]

I'm trying to handle an Api in PhP made with .Net and I user SoapClient to do it.
I can return the functions that it has like this:
$client = new SoapClient($url);
print_r($client->__getFunctions());
But when I'm trying to call a function with parameters it returns me the error:
Uncaught SoapFault exception: [HTTP] Cannot process the message
because the content type 'text/xml; charset=utf-8' was not the
expected type 'application/soap+msbin1'
I use this:
$client = new SoapClient($url, array('soap_version' => 'SOAP_1_2','location'=>$urlWithoutWsdl, $params));
$response = $client->RegisterLoyaltyUser() ;
print_r($response);
So my question really is, do I have to call it with another way or with another library?
EDIT
The api is protected with username and password, maybe this is something I'm missing?
Thanks in advance.
Remove the quotes surrounding SOAP 1_2. It's a constant not a string value

PHP SOAP HEADER Construction (wsse)

I need to write the SOAP Header inside PHP as is described in the picture below:
SOAP Request Example
My first attempt was an array which I would pass to the SoapClient method __setSoapHeaders():
array(
new SoapHeader($namespace, 'UsernameToken', $this->partner->partner_id),
new SoapHeader($namespace, 'USERNAME', $this->partner->email),
new SoapHeader($namespace, 'PASSWORD', $this->partner->password)
);
The error I keep getting when making the actual __soapCall() is:
Fatal error: SOAP Fault: (faultcode: ns1:InvalidSecurity, faultstring: An error was discovered processing the header.)
I just seem unable to get it to work. Any help with this would be greatly appreciated.
Use the WsSecurity project and it'll be done within seconds as you'll be able to easily add the SoapHeader to your existing request,

SOAP: HTTP Not Found when parameter is "SELECT sth FROM"!

I' ve a problem with Soap (I'm using it for the first time!).
I'm trying to solve a problem with SOAP, used to communicate between my site and another.
In SoapServer (on my site) I have a function called say_hello() that takes no argument and returns simply "hello", if I call it from a SoapClient, also with an argument, it works well.
The problem appears if the argument passed is "SELECT everythingyouwanthere FROM otherthingifyouwant". I don't know why but it returns "PHP Fatal error: Uncaught SoapFault exception: [HTTP] Not Found" (404 error).
This started to happen suddenly (or, at least, I don't know the causes). On the server PrestaShop is installed.
Thanks in advance!
P.S. Sorry for my bad english!
try to pass the argument through an array.
Instead of
...
$client = new SoapClient(WSDL);
$client->say_hello("SELECT everythingyouwanthere FROM otherthingifyouwant");
...
try
...
$client = new SoapClient(WSDL);
$client->say_hello(array("parameter_name" => "SELECT everythingyouwanthere FROM otherthingifyouwant"));
...

PHP Service Function Call Error: Object reference not set to an instance of an object

I'm having an annoying difficulty using a webservice written in .Net.
Wsdl can be found: http://services.odeontours.com.tr/OdeonWebService.asmx?wsdl
I want to call CategoryList function and its service description can be found here
I believe it returns a variable .net DataSet data-type..
I've generated wrapper classes by using wsdl2php. Which can be found here
And the code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
include_once './OdeonWebService.php';
$odeonClient = new OdeonWebService();
$auth = new AuthHeader();
$auth->PartnerID = 434;
$auth->UserName = 'xmlReaderGoral';
$auth->Password = "856UD..";
$catListParams = new CategoryList();
$catListRes = $odeonClient->CategoryList($catListParams)->CategoryListResult;
print var_dump($catListRes);
?>
And it says me:
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object.
By the way in service description i noticed that i should pass AuthHeader by header. I have no idea how to do it..
What am i doing wrong??
Thanks in advance..

Help with NuSOAP for a Web Service

I'm trying to do an example web service with NuSOAP in PHP, and I built this example class:
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
and this class for the client:
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/webServiceResta.php');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'Scott'));
// Display the result
print_r($result);
?>
but I seem to get this error, when I run the script:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/webServiceResta.php' : Start tag expected, '<' not found in /opt/lampp/htdocs/prueba.php:5 Stack trace: #0 /opt/lampp/htdocs/prueba.php(5): SoapClient->SoapClient('http://localhos...') #1 {main} thrown in /opt/lampp/htdocs/prueba.php on line 5
I'm using XAMPP on ubuntu, and all the files are in the right place.
Using NuSoap so you need to call nusoap_client :)
$client = new nusoap_client('http://localhost/webServiceResta.php');
You're sending data (Hello,...) that's not proper XML, moreso not proper SOAP WSDL format.
See: http://www.w3.org/TR/wsdl#_wsdl

Categories