SOAP Request from PHP is not working

做~自己de王妃 提交于 2019-12-11 13:34:15

问题


I have a web service available @ http://www.xxxxx/zzzzzzzz/service.asmx and I am trying to send a SOAP request for method - some_function with both the parameters but still not able to get the connection through.

This is my code:

<?php

$param = array('cedula'=>'XXXX','contrasena'=>'YYYYYY');

$client = new SoapClient("http://www.xxxxx/zzzzzzzz/service.asmx?wsdl");
$result = $client->__soapCall('some_function', $param);

print $result;

?>

Error that I'm getting is:

Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /home/zzzz/XXXXXXXXXX.com/uni/index.php:6 Stack trace: #0 /home/zzzz/XXXXXXXXXX.com/uni/index.php(6): SoapClient->__soapCall('some_function' , Array) #1 {main} thrown in /home/zzzz/XXXXXXXXXX.com/uni/index.php on line 6

Please suggest the corrections. Many thanks in advance :)


回答1:


Thanks @dootzky & @lulco. I have solved this. Code below works perfectly fine for me:

<?php

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "http://www.xxxxxxx/zzzzzzzzzz/service.asmx?WSDL";

$login_id = 'XXXX';
$password = 'YYYYYY';

$client = new SoapClient($wsdl_path, array('trace' => 1));

try {
    echo "<pre>\n";
    $result = $client->SOME_FUNCTION(array("request" => array("cedula" => $login_id, "contrasena" => $password)))
    print_r($result);
    echo "\n";
}
catch (SoapFault $exception) {
    echo $exception;      
} 

?>



回答2:


I think you are very close to getting this code to work. I would also give credit to this answer on StackOverflow, looks very similar to what you are asking:

"Object reference not set to an instance of an object" error connecting to SOAP server from PHP

So maybe you should just shoot the method directly, like so:

$client->SOME_FUNCTION(array("request" => array('cedula'=>'XXXX','contrasena'=>'YYYYYY'));

Hope that helps! :)




回答3:


I think it could be problem in wsdl for service SOME_FUNCTION.

Here is the list of services: http://www.xxxxxx/zzzzzzzzzz/service.asmx

All of them work, but SOME_FUNCTION doesn't. Go to url http://www.xxxxxx/zzzzzzzzzz/service.asmx?op=SOME_FUNCTION and try to set parameters and click Invoke. It will not work and throw exception "Object reference not set to an instance of an object.". Then try another service, it will work and return some result.

Example for OTHER_FUNCTION service works:


$param = array('estatus'=>'XXXX');

$client = new SoapClient("http://www.xxxxxx/zzzzzzzzzz/service.asmx?wsdl");
$result = $client->__soapCall('OTHER_FUNCTION', $param);

print_r($result);



来源:https://stackoverflow.com/questions/23339318/soap-request-from-php-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!