Uncaught SoapFault exception: [HTTP] - php

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

Related

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"));
...

Why is Soapclient not recognizing my accountInfo object

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.

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

Troubleshooting SOAP web service

I am trying to invoke the Web Service PersonalDetails_Update by passing an array of values to it. These values are being successfully written to the database that the web service is designed to do. However, it is also supposed to return an ID for the record written to the database. But I don't get anything back. Just a blank screen with no XML or underlying source.
When using getLastRequest, I get this error:
Fatal error: Uncaught SoapFault exception: [Client] Function ("getLastRequest") is not a valid method for this service in
Code used to pass data to web service and request/response headers:
$client->PersonalDetails_Update(array('personaldetails' => $params));
printf("<br/> Request = %s </br>", htmlspecialchars($client->getLastRequest()));
$result = $client->__getLastResponse();
$header = $client->__getLastResponseHeaders();
When using getLastResponse and getLastResponseHeaders, I don't get anything back.
you forgot the "__":
printf("<br/> Request = %s </br>", htmlspecialchars($client->__getLastRequest()));
your soap client thinks "getLastRequest" is a method of a soap service this way, not a soap client method.
also you should tell us what soap client you are using. i assume you use php built-in soap client...
use __soapCall method to be sure, you are making a request to the service:
try {
$result = $client->__soapCall('PersonalDetails_Update', array('personaldetails' => $params));
} catch (SoapFault $exception) {
echo 'soap fault occured: '.$exception->getMessage().'<br/>';
}
you should check if the returned value is a soap fault.. see the manual

Categories