Nusoap复杂对象的的webService制作

推荐网址:
http://www.scottnichol.com/nusoapprogwsdl.htm
摘抄部分如下:
服务器端程序
<? php
//  Pull in the NuSOAP code
require_once ( ' nusoap.php ' );
//  Create the server instance
$server   =   new  soap_server();
//  Initialize WSDL support
$server -> configureWSDL( ' hellowsdl2 ' ,   ' urn:hellowsdl2 ' );
//  Register the data structures used by the service
$server -> wsdl -> addComplexType(
    
' Person ' ,
    
' complexType ' ,
    
' struct ' ,
    
' all ' ,
    
'' ,
    
array (
        
' firstname '   =>   array ( ' name '   =>   ' firstname ' ,   ' type '   =>   ' xsd:string ' ) ,
        
' age '   =>   array ( ' name '   =>   ' age ' ,   ' type '   =>   ' xsd:int ' ) ,
        
' gender '   =>   array ( ' name '   =>   ' gender ' ,   ' type '   =>   ' xsd:string ' )
    )
);
$server -> wsdl -> addComplexType(
    
' SweepstakesGreeting ' ,
    
' complexType ' ,
    
' struct ' ,
    
' all ' ,
    
'' ,
    
array (
        
' greeting '   =>   array ( ' name '   =>   ' greeting ' ,   ' type '   =>   ' xsd:string ' ) ,
        
' winner '   =>   array ( ' name '   =>   ' winner ' ,   ' type '   =>   ' xsd:boolean ' )
    )
);
//  Register the method to expose
$server -> register( ' hello ' ,                      //  method name
     array ( ' person '   =>   ' tns:Person ' ) ,            //  input parameters
     array ( ' return '   =>   ' tns:SweepstakesGreeting ' ) ,      //  output parameters
     ' urn:hellowsdl2 ' ,                           //  namespace
     ' urn:hellowsdl2#hello ' ,                     //  soapaction
     ' rpc ' ,                                      //  style
     ' encoded ' ,                                  //  use
     ' Greet a person entering the sweepstakes '          //  documentation
);
//  Define the method as a PHP function
function  hello( $person ) {
    
$greeting   =   ' Hello,  '   .   $person [ ' firstname ' .
                
' . It is nice to meet a  '   .   $person [ ' age ' .
                
'  year old  '   .   $person [ ' gender ' .   ' . ' ;
    
    
$winner   =   $person [ ' firstname ' ==   ' Scott ' ;

    
return   array (
                
' greeting '   =>   $greeting ,
                
' winner '   =>   $winner
                );
}
//  Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA   =   isset ( $HTTP_RAW_POST_DATA ?   $HTTP_RAW_POST_DATA   :   '' ;
$server -> service( $HTTP_RAW_POST_DATA );
?>

客户端程序:
<? php
//  Pull in the NuSOAP code
require_once ( ' nusoap.php ' );
//  Create the client instance
$client   =   new  soapclient( ' http://localhost/phphack/hellowsdl2.php?wsdl ' ,   true );
//  Check for an error
$err   =   $client -> getError();
if  ( $err ) {
    
//  Display the error
     echo   ' <h2>Constructor error</h2><pre> '   .   $err   .   ' </pre> ' ;
    
//  At this point, you know the call that follows will fail
}
//  Call the SOAP method
$person   =   array ( ' firstname '   =>   ' Willi ' ,   ' age '   =>   22 ,   ' gender '   =>   ' male ' );
$result   =   $client -> call( ' hello ' ,   array ( ' person '   =>   $person ));
//  Check for a fault
if  ( $client -> fault) {
    
echo   ' <h2>Fault</h2><pre> ' ;
    
print_r ( $result );
    
echo   ' </pre> ' ;
else  {
    
//  Check for errors
     $err   =   $client -> getError();
    
if  ( $err ) {
        
//  Display the error
         echo   ' <h2>Error</h2><pre> '   .   $err   .   ' </pre> ' ;
    } 
else  {
        
//  Display the result
         echo   ' <h2>Result</h2><pre> ' ;
        
print_r ( $result );
    
echo   ' </pre> ' ;
    }
}
//  Display the request and response
echo   ' <h2>Request</h2> ' ;
echo   ' <pre> '   .   htmlspecialchars ( $client -> request ,  ENT_QUOTES)  .   ' </pre> ' ;
echo   ' <h2>Response</h2> ' ;
echo   ' <pre> '   .   htmlspecialchars ( $client -> response ,  ENT_QUOTES)  .   ' </pre> ' ;
//  Display the debug messages
echo   ' <h2>Debug</h2> ' ;
echo   ' <pre> '   .   htmlspecialchars ( $client -> debug_str ,  ENT_QUOTES)  .   ' </pre> ' ;
?>

转载于:https://www.cnblogs.com/likwo/archive/2009/09/24/1573261.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值