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

使用zeng studio 创建的php调用webservice soap简单实例

2011-11-05 22:15 1086 查看
这两天一直在研究webservice soap是个什么东西,究竟怎么创建webservice,又如何用php调用webservice的借口,经过奋战,终于总算弄懂一点的。然后我做了一个webservice应用,然后使用php调用其借口,其功能只是简单的用户注册。

webservice究竟是个什么东东,自己百度吧。首先我来讲讲创建这个webservice的难点,难点就在于如何写出一个正确可用的WSDL文件,只要有了这个WSDL文件,那么其他的工作就一点都不新鲜了,就像你平时编程一样。

当你看看WSDL文件的时候,可能你头都大了,一大串代码,根本就不知道是什么。后来百度了一下,才知道这个东西只有牛人才可以写出来,我们这些一般的人物是可以用工具生成的,推荐zeng studio。我下的是7.1版的,发现和网上的教程根本不一样(他们可能使用的是旧版本),搞了半天都不知道在哪里生成WSDL文件,网上教程上说的大多数是使用export或者是tool,但你会发现较新版本的这两个都不管用。下面我就来演示一下如何生成这个WSDL文件。

首先,肯定是要创建PHP工程的。然后我们来创建webservice服务器端的文件,新建一个Class,代码如下:

WSDL<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://localhost/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="soap" targetNamespace="http://localhost/soap/">
<wsdl:types>
<xsd:schema targetNamespace="http://localhost/soap/">
<xsd:element name="NewOperation">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="in" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="NewOperationResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="RegisterRequest">

<wsdl:part name="username" type="xsd:string"></wsdl:part>
<wsdl:part name="password" type="xsd:string"></wsdl:part>
<wsdl:part name="email" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:message name="RegisterResponse">

<wsdl:part name="RegisterResponce" type="xsd:boolean"></wsdl:part>
</wsdl:message>
<wsdl:portType name="soap">
<wsdl:operation name="Register">
<wsdl:input message="tns:RegisterRequest"/>
<wsdl:output message="tns:RegisterResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="soapSOAP" type="tns:soap">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Register">
<soap:operation soapAction="http://localhost/soap/Register"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="soap">
<wsdl:port binding="tns:soapSOAP" name="soapSOAP">
<soap:address location="http://localhost/soap/server.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: