您的位置:首页 > 编程语言 > PHP开发

PHP利用SOAP进行webservice开发(客户端)

2013-07-10 10:32 429 查看
参考:http://blog.sina.com.cn/s/blog_777f9dbb01010fd1.html

配置

windows php.ini配置:

extension = php_soap.dll
extension = php_curl.dll
extension = php_openssl.dll
linux php.ini配置:

extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"

extension = "soap.so"

并把soap.so放到/usr/local/lib/php/extensions/no-debug-non-zts-20060613目录下

php支持soap参考:/article/8529120.html

示例-WSDL模式:

<?php
header("content-type:text/html;charset=utf-8");

ini_set( 'default_socket_timeout', 7 ); // timeout

ini_set("soap.wsdl_cache_enabled", "0"); // no cache

$client = new SoapClient("http://url/ooxx.asmx?wsdl");
$param =array('参数'=>'值','参数'=>'值');
$p =$client->__soapCall('调用方法名',array('parameters'=> $param)); // 注意,这里一定要再次组成一个array,才能把参数名正确发送出去,不然发送的参数名为param1,param2...

print_r($p->调用方法名Result);
?>

示例-非WSDL模式:

<?php
header("content-type:text/html;charset=utf-8");

ini_set( 'default_socket_timeout', 7 ); // timeout

ini_set("soap.wsdl_cache_enabled", "0"); // no cache

$client = new SoapClient( "http://url/ooxx.asmx?wsdl", array( 'proxy_host' => "10.100.32.20", 'proxy_port' => 9080 ) );
$param =array('参数'=>'值','参数'=>'值');
$p =$client->__soapCall('调用方法名',array('parameters'=> $param)); // 注意,这里一定要再次组成一个array,才能把参数名正确发送出去,不然发送的参数名为param1,param2...

print_r($p->调用方法名Result);
?>

手册上有人对上面加粗部分代码(函数参数)的注释

注释1:

If your service is a .NET doc/lit, which means the input message has a single part named 'parameters' that is a structure that wraps the parameters.  Your call should look like this:




<?php




$params = array('param_name_1'=>$val_1,'param_name_2'=>$val_2);


$client->call('MethodName',
array('parameters'=>$params));




?>






注释2:




Note that calling __soapCall and calling the generated method from WSDL requires specifying parameters in two different ways.




For example, if you have a web service with method login that takes username and password, you can call it the following way:


<?php


$params= array('username'=>'name','password'=>'secret');


$client->login($params);


?>




If you want to call __soapCall, you must wrap the arguments in another array as follows:


<?php


$client->__soapCall('login',
array($params));


?>



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: