Fatal error: Uncaught SoapFault exception: [soap:Server] Fault occurred while processing - php

I use this code
error_reporting(E_ALL);
ini_set('display_errors', 1);
$params = array(
'username' => 'username',
'password' => 'password',
'cocNo' => '1060907A'
);
$client = new SoapClient('URL/?wsdl',array('trace'=>1));
//$response = $client->__getTypes();
$response = $client->__getFunctions();
pint_r($response);
and get this successful response:
Array ( [0] => verifyResponse verify(verify $parameters) )
but when i use this code
$response = $client->__soapcall('verify',array($params));
I got this response error
Fatal error: Uncaught SoapFault exception: [soap:Server] Fault occurred while processing. in /PATH/index.php:22
Stack trace: #0 /PATH/index.php(22): SoapClient->__soapCall('verify', Array) #1 {main} thrown in /PATH/index.php on line 22
What is wrong with my call?

According to $client->__getTypes() you are missing an 'arg0' element in your data structure. Change your code to:
try
{
$response = $client->verify(array('arg0' => $params));
}
catch(Exception $e)
{
var_dump($e->getMessage());
}

Related

There is an error in SOAP-request by PHP

This request:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Buy xmlns="http://tempuri.org/">
<perf>
<param1>1111</param1>
<param2>2222</param2>
</perf>
</Buy>
</soap:Body></soap:Envelope>
I create request with SoapClient:
$client = new SoapClient("http://0.0.0.0:8080/Service1.asmx?wsdl",
array(
'trace' => true,
'exceptions'=>true
));
Function "getTypes" and "getFunctions" work correct
$types = $client->__getTypes();
$functions = $client->__getFunctions ();
I'm creating object and I'm waiting result:
$std = new stdClass();
$std->param1 = '1111';
$std->param2 = '2222';
ini_set("soap.wsdl_cache_enabled", "0"); // disallow cache WSDL
$result = $client->Buy( array('perf' => $std ) );
var_dump($result); exit;
I got an error: SoapFault:
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/index.php:86 Stack trace: #0 [internal function]: SoapClient->__doRequest('__call('Buy', Array) #2 /var/www/index.php(86): SoapClient->Buy(Array) #3 {main} thrown in /var/www/index.php on line 86
In the logs of apache:
PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/index.php:86\nStack trace:\n#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://0.0.0...', 'http://tempuri....', 1, 0)\n#1 /var/www/index.php(86): SoapClient->__call('Buy', Array)\n#2 /var/www/index.php(86): SoapClient->Buy(Array)\n#3 {main}\n thrown in /var/www/index.php on line 86
Please, help me), may be, I created object with parameters not correct?
Try not to mix arrays and objects. Check this:
$result = $client->Buy( array('perf' => array('param1' => '1111', 'param2' => '2222')) );
Or this:
$result = $client->Buy( (object) array('perf' => (object) array('param1' => '1111', 'param2' => '2222')) );

SoapFault exception: [HTTP] Authorization Required

I am using third party SOAP API to get users details
$wsdl = 'https://sample.ifuture.com/sites/sample.xxxx.com/api/isession.php?wsdl';
$client = new SoapClient($wsdl, array ( 'username'=>'testusername', 'password'=>'testpassword'));
print_r($client->__getFunctions());
When I use SoapClient() I am successfully connect to WSDL, last statement return the function list of the WSDL.
Result
Array
(
[0] => boolean iLoggedOn(string $session)
[1] => boolean iLogOff(string $session)
[2] => boolean iLogOn(string $session, string $username, string $password)
[3] => boolean iPasswd(string $session, string $username, string $password)
[4] => list(boolean $return, string $message) iSync(string $username, string $action, string $values)
)
Now I am trying to use the SOAP __Call() to invoke soap method
$param = array(
"sessionid" =>"12345678900987654321abcisfetul12",
"username" =>"test",
"password"=>"test");
$client->__Call('iLogOn', $param);
The execution of above statement generates an error as mentioned below
Fatal error: Uncaught SoapFault exception: [HTTP] Authorization Required in /opt/lampp/htdocs/demo/saop/index.php:79 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://sample....', 'https://sample....', 1, 0) #1 /opt/lampp/htdocs/demo/saop/index.php(79): SoapClient->__call('iLogOn', Array) #2 {main} thrown in /opt/lampp/htdocs/demo/saop/index.php on line 79
Looking forward for appropriate solution.

PHP __SoapCall issue

I have a simple service using php and Soap
There's a function named getPrice in my SOAP SERVER
This is getPrice :
function getPrice($productISBN, $param)
{
return $productISBN;
}
$kks = new SoapServer(null, array('uri' => "urn://my/webservice/shop"));
$kks->addFunction( array(
'getPrice',
'reserveProduct',
'inquiryPostPrice',
'registerPostOrder'
) );
$kks->addFunction(SOAP_FUNCTIONS_ALL);
$kks->handle();
and this is my client file -This is in /kkc folder :
$client = new SoapClient(null, array(
'location' => "http://example.com/webservice/kks/shop.php",
'uri' => "urn://my/webservice/shop"
) );
var_dump( $client->__soapCall('getPrice', array(123456789, $param) ) );
//$param is a string
but I'll get this error in client :
Fatal error: Uncaught SoapFault exception: [HTTP] Internal Server
Error in /example.com/webservice/kkc/client.php:28 Stack trace:
#0 [internal function]: SoapClient->__doRequest('__soapCall('getPrice', Array)
#2 {main} thrown in /example.com/public_html/webservice/kkc/client.php on line 28
I have two other files like this and there's everything is fine...
Would you please let me know what's wrong here?
Thanks in Advance

WebService banguat.gob.gt

Thank you all in advance for the help:
I have this code:
require_once('include/nusoap/lib/nusoap.php');
$soapclient = new soapclient('http://www.banguat.gob.gt/variables/ws/TipoCambio.asmx');
print_r( $soapclient->call( 'TipoCambioDia' ) );
and gives me this error:Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.banguat.gob.gt/variables/ws/TipoCambio.asmx' : Premature end of data in tag html line 3 in C:\xampp\htdocs\cambio_moneda\cambio_moneda.php:3 Stack trace: #0 C:\xampp\htdocs\cambio_moneda\cambio_moneda.php(3) : SoapClient->SoapClient('http://www.bang...') #1 {main} thrown in C:\xampp\htdocs\cambio_moneda\cambio_moneda.php on line 3
Then I tried with this code:
require_once('include/nusoap/lib/nusoap.php');
$soapclient = new soapclient();
$result = $soapclient->call( 'TipoCambioDia' , array(), "http://www.banguat.gob.gt/variables/ws/TipoCambio.asmx?op=TipoCambioDia", "http://www.banguat.gob.gt/variables/ws/TipoCambio.asmx?op=TipoCambioDia");
print_r( $result );
And I get this error results:Fatal error: Uncaught SoapFault exception: [Client] SoapClient::SoapClient(): Invalid parameters in C:\xampp\htdocs\cambio_moneda\cambio_moneda.php:3 Stack trace: #0 C:\xampp\htdocs\cambio_moneda\cambio_moneda.php(3) : SoapClient->SoapClient() #1 {main} thrown in C:\xampp\htdocs\cambio_moneda\cambio_moneda.php on line 3
What I want to accomplish is to get the exchange rate plus the date and store it in a variable
Thanks to all
The reason for the fatal error is that the URL you are using to create $soapclient is not a WSDL file. You will need to change it (note the ?WSDL in the URL):
$soapclient = new soapclient('http://www.banguat.gob.gt/variables/ws/TipoCambio.asmx?WSDL');
Next, to get "TipoCambioDia" call, you need to use it directly, i.e.:
$soapclient->TipoCambioDia()
Doing this will return in a stdObject:
stdClass Object
(
[TipoCambioDiaResult] => stdClass Object
(
[CambioDolar] => stdClass Object
(
[VarDolar] => stdClass Object
(
[fecha] => 30/01/2015
[referencia] => 7.65538
)
)
[TotalItems] => 1
)
)

Write username to httpheader for web service authetification with php

My code:
$url = "http://x.x.x.x/ws/special/Service?wsdl";
$context = stream_context_create(array('http' => array( 'username' => "jonas" )));
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
$res = $client->__soapCall("getinfo",array('counter'=>'10'));
Error:-
Fatal error: Uncaught SoapFault exception: [S:Server] missing parameter
'username' in C:\xampp\htdocs\test.php:7 Stack trace: #0
C:\xampp\htdocs\test.php(7): SoapClient->__soapCall('getAsinfo...', Array)
#1 {main} thrown in C:\xampp\htdocs\test.php on line 7
How to write to http header?

Categories