Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当身份验证正常时,php soap客户端获取服务器java.lang.NullPointerException_Java_Php_Web Services_Authentication_Soap Client - Fatal编程技术网

当身份验证正常时,php soap客户端获取服务器java.lang.NullPointerException

当身份验证正常时,php soap客户端获取服务器java.lang.NullPointerException,java,php,web-services,authentication,soap-client,Java,Php,Web Services,Authentication,Soap Client,如果要将对象发送到webmethod以将其用作参数: 示例:发送将在服务器中表示为类的对象,如下所示: $creditCard = new stdClass(); $creditCard->number="705"; $creditCard->expiryDate="03/10/2019"; $creditCard->controlNumber=9; $param = array("creditCard" => $creditCard);

如果要将对象发送到webmethod以将其用作参数: 示例:发送将在服务器中表示为类的对象,如下所示:

   $creditCard = new stdClass();
   $creditCard->number="705";
   $creditCard->expiryDate="03/10/2019";
   $creditCard->controlNumber=9;
   $param = array("creditCard" => $creditCard);

   $Response = $client->__soapCall('valider', array($param)); 

您将无法获得服务器中的CreditCard类的任何属性,并且每次执行creditClass.getNumber()时或者尝试使用访问器时,您将收到一个空指针错误,因为您的对象没有真正创建。

要解决此问题,您必须修改服务器Web服务,而不是客户端:您必须添加平凡的jax ws注释@webParam:

  public String valider(@WebParam(name = "creditCard")CreditCard creditCard){ ... }
您的PHPSOAPClient代码非常简单:(如果您想要更高的安全性,您必须对凭证进行编码,或者使用其他方式进行身份验证,如摘要身份验证或其他jax ws安全实现)

   try { 
      $opts = array (
        'http' => [
        'header' => "username: myrealname\r\n".
                   'password: pass1myrealpassword'] 
        );
      $par= array(
            'trace' => 1,
              'exceptions' =>0,
             'soap_version'   => SOAP_1_1,
             'connection_timeout' => 1800,
             'stream_context' => stream_context_create($opts),
               );

      $client = new SoapClient($wsdl,$par);
     //...... and call your service method as you do