1,实例
Php代码
try { $client = new SoapClient( null, array('location' =>'http://localhost/oms07/index.php?r=api', 'uri' =>'http://localhost/oms07') ); $results = $client->__soapCall('getFailParts', array('startTime'=>'2011-10-24','endTime'=>'2011-10-25')); var_dump($result);} catch (Exception $e) { printf("Message = %s",$e->__toString());}2,调试 SOAP扩展当前已经提供调试功能, “之前在使用soap时,调试时无法得知返回错误信息,只会得到looks like we got no XML document。最近还想写个扩展用于获取返回响应信息,再查看PHP文档原来可以这样.手册是个好东西。” Php代码
/** * 设置参数array("trace"=>true)用于调试 * __getLastRequest 返回请求信息 * __getLastResponse 返回响应信息包括报错信息都会返回 */try{ $client = new SoapClient($server,array("trace"=>true));//此处trace一定要开,否则调试无效 $pam = ['code' => '56ren', 'orderNO' => '123', 'parameters' => '{"type":"00","name":"abc"}']; //此处参数 //手册原话是 //An array of the arguments to pass to the function. This can be either an ordered or an associative array. Note that most SOAP servers require parameter names to be provided, in which case this must be an associative array. //要求和SOAPserver 提供的参数名称完成一致,否则报错 $result = $client->__soapCall('Order' , [ 'parameters' => $pam]); //请求参数,必须套个数组,否则默认会第一个参数丢失,此处就是参数code不能发送}catch(SoapFault $e){ echo $client->__getLastRequest();//查看发送值 echo ''; echo $client->__getLastRequestHeaders ();//发送头,可以看看地址是否出错 echo ''; echo $client->__getLastResponse();//自己查看php手册 echo ''; echo $client->__getLastResponseHeaders ();//自己查看php手册 echo ''; echo $e->getMessage();}
若是没有异常报错,返回,可把打印信息提前,比如__soapCall()后面
$result = $client->__soapCall('OrderRelease' , [ 'parameters' => $pam]); //请求参数// dump($client->__getFunctions()); echo $client->__getLastRequest(); echo $client->__getLastRequestHeaders (); echo $client->__getLastResponse(); echo $client->__getLastResponseHeaders (); die;
这个调试可以直接查看发送的参数值,如何打印发送的参数名,暂时没找到怎么实现