PHP SOAP HEADER Construction (wsse) - php

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,

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

Very weird SoapClient problem

try
{
$client = new \SoapClient($wsdlUrl, array(
'cache_wsdl' => 0, 'exceptions' => true, 'trace' => true));
$client->getPage($parameter);
}
catch(\Exception $e)
{
die("exception");
}
Okay this is what executes the SOAP request. $wsdlUrl holds the WSDLs URL and $parameter keeps an XML document.
And everything works like a charm!
Now I just add few more nodes to the XML document in $parameter and I get a fatal error.
This is not so weird necessarily, but what is weired is the combination of following three observations:
1) exceptions is set to true .... but no Exception is thrown / this was b/c I forgot to place a backslash before Exception in the catch statement.
2) instead an error is logged:
PHP Fatal error: SoapClient::SoapClient():
'uri' option is required in nonWSDL mode in /var/w[...]
3) but the WSDL url is provided and of course valid, as all works again just fine after skipping the adding of the new nodes. they don't affect the wsdl parameter.
Okay, I tracked down the source of the problem. There is no satisfying answer really to that question but few things to learn! :)
The important thing is that the request has been sent and processed by the SOAP server.
But the server responds with an error.
So, obviously, even though a fatal error regarding no wsdl and no connection parameter is triggered doesn't mean no request has been sent - which is very counter logical in my opinion b/c if no wsdl is provided and no connection params as well, then how could the request be executed?
EDIT
There is another bug in the code. I forgot to place a backslash before Exception! Without it's not referring to the Exception class.
Then an exception is thrown and caught.

soap call error

I'm trying to call a function via a SOAP webservice. The following code is run:
$return_soap = $this->soap->__soapCall($soap_function, $params);
I have also tryed:
$return_soap = call_user_func_array(array($this->soap,$soap_function),$params);
The headers are good, and i'm sending the following parameters:
$params = array('customer_info'=>array_values( 'name'=>'Stephen de Tester',
'i_parent'=>12695,
'iso_4217'=>'EU',
'i_customer_type'=>1,
'opening_balance'=>'10.00',
'i_customer_class'=>1));
i have tryed it without array_values and a bunch of other combinations. I always get the following message:
( [error] => SOAP-ERROR: Encoding: object hasn't 'customer_info' property )
However if i try a webservice call without parameters it all seems to work perfectly...
Could you guys help me in the right direction?
Could you supply the url to the WSDL file for the service? I'm not quite sure from the error but it's either saying that you haven't supplied a customer_info property or that you've supplied a customer_info property on a method that doesn't accept that property. Either way a peek at the WSDL should help make it clearer.

Categories