项目的需求,需要和一个.net系统进行数据交换,合作方提供了一个webservice接口。这个与一般的php post或get传值再查库拿数据的思路有点不一样,需要用到soap模块,处理方法也很简单,就是有一些需要注意的事情。
首先确认你的php.ini开启了.soap,就是 extension=php_soap.dll 这前面的分号去咯。
代码很简单:
soap_defencoding = 'utf-8'; $client->decode_utf8 = false; $client->xml_encoding = 'utf-8'; $param = array('param1'=>'01', 'param2'=>'02');//$param[param1]=01;//$param[param2]=02;//$result = $client->__soapcall(getarticle, array( $param ));$result = $client->__call(getarticle, array( $param ));if (is_soap_fault($result)){ trigger_error(soap fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring}), e_user_error);}else{ $data = $result->getarticleresult; //这里返回的是类,必须使用->得到元素的值 print_r($data);}?>
需要注意的一点是,参数是数组外再包一层数组,就是 array( array() )
附soap接口的一些参数:
以下是 soap 1.2 请求和响应示例。所显示的占位符需替换为实际值。
post /searchservice.asmx http/1.1host: 202.105.183.61content-type: text/xml; charset=utf-8content-length: lengthsoapaction: http://tempuri.org/gettrafficviolationinfo string string
http/1.1 200 okcontent-type: text/xml; charset=utf-8content-length: length string
http://www.bkjia.com/phpjc/752322.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/752322.htmltecharticle项目的需求,需要和一个.net系统进行数据交换,合作方提供了一个webservice接口。这个与一般的php post或get传值再查库拿数据的思路有点不一...