日期:2012-06-01  浏览次数:20497 次

客户端

代码:
01.<?php
02.header ( "Content-Type: text/html; charset=utf-8" );
03./*
04.* 指定WebService路径并初始化一个WebService客户端
05.*/
06.$ws = "http://soap/soapCspMessage.php?wsdl";
07.$client = new SoapClient ( $ws, array ('trace' => 1, 'uri' => 'http://www.zxsv.com/SoapDiscovery/' ) );
08./*
09.* 获取SoapClient对象引用的服务所提供的所有方法
10.*/
11.echo ("SOAP服务器提供的开放函数:");
12.echo ('<pre>');
13.var_dump ( $client->__getFunctions () );
14.echo ('</pre>');
15.echo ("SOAP服务器提供的Type:");
16.echo ('<pre>');
17.var_dump ( $client->__getTypes () );
18.echo ('</pre>');
19.echo ("执行GetGUIDNode的结果:");
20.//$users = $client->GetUsers();
21.//var_dump($HelloWorld );
22.$parameters = array('uname'=>'zxsv',"upassword"=>'123');
23.$out = $client->HelloWorld($parameters);
24.$datadb = $out->HelloWorldResponse;
25.var_dump($out);
26.?>

服务端

代码:

01.<?php
02.class Member
03.{
04.public $UserId;
05.public $Name;
06.public function __construct($parmas){
07.$this->UserId = $parmas[0];
08.$this->Name = $parmas[1];
09.}
10.}
11.$servidorSoap = new SoapServer('testphp.xml',array('uri' => 'http://www.TestPHP.com/','encoding'=>'utf-8','soap_version' => SOAP_1_2 ));
12.$servidorSoap->setClass(Testphp);
13.$servidorSoap->handle();
14.class Testphp {
15.public function HelloWorld($uid){
16.return array('HelloWorldResult'=>"mystring".$uid->{'uname'}.' and '.$uid->{'upassword'});
17.}
18.public function GetMember($uid){
19.$s=array();
20.for($i=0;$i<$uid->{'uid'};$i++){
21.$s[] =&new Member(array($i, $uid->{'uname'}.'我测试'.$i));
22.}
23.return   array('GetMemberResult'=>$s);
24.}
25.}
26.?>

到这里应该都看的懂吧
下面是WSDL文件

代码:

001.<?xml version="1.0" encoding="utf-8"?>
002.<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.TestPHP.com/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.TestPHP.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
003.<wsdl:types>
004.<s:schema elementFormDefault="qualified" targetNamespace="http://www.TestPHP.com/">
005.<s:element name="HelloWorld">
006.<s:complexType>
007.<s:sequence>
008.<s:element minOccurs="0" maxOccurs="1" name="uname" type="s:string" />
009.<s:element minOccurs="0" maxOccurs="1" name="upassword" type="s:string" />
010.</s:sequence>
011.</s:complexType>
012.</s:element>
013.<s:element name="HelloWorldResponse">
014.<s:complexType>
015.<s:sequence>
016.<s:element minOccurs="0" maxOccurs="1"