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

参考: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参考: http://blog.csdn.net/bytxl/article/details/9284123


示例-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));

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值