博客专区 > LiMXHS的博客 > 博客详情
PHP 自身扩展 SOAP使用详解 (二)
LiMXHS 发表于4年前
PHP 自身扩展 SOAP使用详解 (二)
  • 发表于 4年前
  • 阅读 1610
  • 收藏 13
  • 点赞 0
  • 评论 0

IBM Bluemix免费试用!>>>   

php 的 soap 返回数组:

services.php文件:

<?php
class services {  
  /**
    * Getdnstatus one string from each other
    * 
    * @param string $dn The first string of the subtraction
    * @return array The status of the tel
   */
  public function getdnstatus($dn){
  	if($dn == "8101"){
  		$status_arr = array("1","通话","1");
  	}else{
  		$status_arr = array("0","空闲","0");
  	}
  	return serialize($status_arr);
  }
}  
  $server = new SoapServer('service.wsdl', array('soap_version' => SOAP_1_2));  
  $server->setClass("services");  
  $server->handle();  
?>

service.wsdl文件:

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

<!-- WSDL file generated by Zend Studio. -->

<definitions name="service" targetNamespace="urn:service" xmlns:typens="urn:service" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
	<message name="getdnstatus">
		<part name="dn" type="xsd:string"/>
	</message>
	<message name="getdnstatusResponse">
		<part name="getdnstatusReturn" type="xsd:anyType"/>
	</message>
	<portType name="servicesPortType">
		<operation name="getdnstatus">
			<documentation>
				Getdnstatus one string from each other
			</documentation>
			<input message="typens:getdnstatus"/>
			<output message="typens:getdnstatusResponse"/>
		</operation>
	</portType>
	<binding name="servicesBinding" type="typens:servicesPortType">
		<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
		<operation name="getdnstatus">
			<soap:operation soapAction="urn:servicesAction"/>
			<input>
				<soap:body namespace="urn:service" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
			</input>
			<output>
				<soap:body namespace="urn:service" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
			</output>
		</operation>
	</binding>
	<service name="serviceService">
		<port name="servicesPort" binding="typens:servicesBinding">
			<soap:address location="http://10.1.7.153/soap/services.php"/>
		</port>
	</service>
</definitions>

客户端文件:client.php

<?php
  //$client = new SoapClient('http://10.1.7.153/soap/service.wsdl');   
  $client = new SoapClient("http://10.1.7.153/soap/services.php?WSDL");  
  try {  
  	$result = array();
	$result = $client->getdnstatus('8101');
	var_dump(unserialize($result));
  } catch(SoapFault $e) {  
	print "Sorry an error was caught executing your request: {$e->getMessage()}";  
  } 
?>

 

标签: php soap webservice
共有 人打赏支持
粉丝 0
博文 15
码字总数 4290
×
LiMXHS
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: