首页 > 编程语言 >PHP5 soap web services

PHP5 soap web services

时间:2023-03-27 20:01:07浏览次数:37  
标签:__ soaplib server print import services PHP5 soap

一.开发环境:

 1 WAMPserver PHP5.3 + apache + mysql的集成环境

 2.Eclipse + PHP插件

 3。python2.5和PHP5语言版本

二:开发代码

 1.python 做一个服务端,发布为python web services.


代码如下:

import soaplib

import soaplib.core

from soaplib.core.service import rpc, DefinitionBase,soap

from soaplib.core.model.primitive import String, Integer

from soaplib.core.server import wsgi

from soaplib.core.model.clazz import Array



class HelloWorldService(DefinitionBase):

 @soap(String,_returns=String)

 def say_hello(self,name):

 results = "hello,"+name;

 return results



if __name__=='__main__':

 try:

 from wsgiref.simple_server import make_server

 soap_application = soaplib.core.Application([HelloWorldService], 'tns')

 wsgi_application = wsgi.Application(soap_application)

 server = make_server('10.21.237.120', 8010, wsgi_application)

 print "8010........."

 server.serve_forever()

 except ImportError:

 print "Error: example server code requires Python >= 2.5"


WSDL地址:http://10.21.237.120:8010/server?wsdl


2.PHP5作为php 客户端调用python web services

代码如下:


<?php


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


 try {

 //$client = new SoapClient("HelloService.wsdl",array('encoding'=>'UTF-8'));

 $client = new SoapClient("http://10.21.237.120:8010/server?wsdl",array('encoding'=>'utf-8'));

// var_dump($client->__getFunctions());

// print("<br/>"); 

// var_dump($client->__getTypes());

// print("<br/>"); 


 $parm1 = "KING";

 $param = array('name' => $parm1);

 $arr = $client->say_hello($param);

// print_r($arr); 

 $ar = get_object_vars($arr);

 print("<br/>"); 

// print_r($ar);

 print("<br/>"); 

 echo $ar["say_helloResult"];


 } catch (SOAPFault $e) {


 print $e;

 }

?>


三:soap环境的搭建


 这个比较烦恼的事情,WAMP集成了PHP5自带了soap扩展,所谓的扩展就是有soap 的功能!!

 python 端用的是soaplib,官方文档有点错误的,我的代码是根据官方代码修改了下!!

四:遇到问题怎么办

 你可以邮件给我或者QQ1019990976,技术分享,广交天下好朋友。

 我已经录制了视频。

标签:__,soaplib,server,print,import,services,PHP5,soap
From: https://blog.51cto.com/u_16034393/6153104

相关文章