PHP中soap的用法实例

2015 年 1 月 1 日3750

软机网 > 代码编程 > PHP >

PHP中soap的用法实例

2014-10-25 09:15 出处:软机网 人气: 

软机网(http://http://www.zjjv.com//):PHP中soap的用法实例

本文实例讲述了PHP中soap的用法,分享给大家供大家参考。具体用法分析如下:

PHP 使用soap有两种方式。

一、用wsdl文件

服务器端:

复制代码 代码如下:

<?php

class service

{

public function HelloWorld()

{

return "Hello";

}

public function Add($a,$b)

{

return $a+$b;

}

}

$server=new SoapServer('soap.wsdl',array('soap_version' => SOAP_1_2));

$server->setClass("service");

$server->handle();

?>

资源描述文件,可以用工具(zend studio)生成。其实就是一个xml文件。

复制代码 代码如下:

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions xmlns:soap="http://http://www.zjjv.com///wsdl/soap/" xmlns:tns="http://localhost/interface/" xmlns:wsdl="http://http://www.zjjv.com///wsdl/" xmlns:xsd="http://http://www.zjjv.com///2001/XMLSchema" targetNamespace="http://localhost/interface/">

<wsdl:types>

<xsd:schema targetNamespace="http://localhost/interface/">

<xsd:element>

<xsd:complexType>

<xsd:sequence>

<xsd:element type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

<xsd:element>

<xsd:complexType>

<xsd:sequence>

<xsd:element type="xsd:string"/>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

<xsd:element>

<xsd:complexType>

<xsd:sequence>

<xsd:element type="xsd:int"></xsd:element>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

<xsd:element>

<xsd:complexType>

<xsd:sequence>

<xsd:element type="xsd:int"></xsd:element>

</xsd:sequence>

</xsd:complexType>

</xsd:element>

</xsd:schema>

</wsdl:types>

<wsdl:message> <wsdl:part type="xsd:int"></wsdl:part>

<wsdl:part type="xsd:int"></wsdl:part>

</wsdl:message>

<wsdl:message>

<wsdl:part type="xsd:int"></wsdl:part>

</wsdl:message>

<wsdl:portType> <wsdl:operation>

<wsdl:input message="tns:AddRequest"></wsdl:input>

<wsdl:output message="tns:AddResponse"></wsdl:output>

</wsdl:operation>

</wsdl:portType>

<wsdl:binding type="tns:TestSoap">

<soap:binding

transport="http://http://www.zjjv.com///soap/http" />

<wsdl:operation>

<soap:operation soapAction="http://localhost/interface/Add" />

<wsdl:input>

<soap:body use="literal"

namespace="http://localhost/interface/" />

</wsdl:input>

<wsdl:output>

<soap:body use="literal"

namespace="http://localhost/interface/" />

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

<wsdl:service>

<wsdl:port binding="tns:soapSOAP">

<soap:address location="http://localhost/interface/myservice.php"/>

</wsdl:port>

</wsdl:service>

</wsdl:definitions>

客户端调用:

复制代码 代码如下:

<?php

$soap = new SoapClient('http://localhost/interface/soap.wsdl');

echo $soap->Add(1,2);

?>

二、不用wsdl文件

服务器端:

复制代码 代码如下:

  

分享给小伙伴们:

本文标签:

PHP,soap,用法/">PHP,soap,用法

相关文章

</p> <p> 评论</p> <p>

发表评论愿您的每句评论,都能给大家的生活添色彩,带来共鸣,带来思索,带来快乐。

评论列表

0 0