PHP 创建webservice 在客户端调用的问题

独立级IT民工 2012-12-12 07:59:18
soapserver.php


<?php
ini_set("soap.wsdl_cache_enabled", "0");
class service
{
public function HelloWorld() {
return "Hello";
}
public function Add($a,$b) {
return $a+$b;
}
}
$server=new SoapServer('TestSoap.wsdl',array('soap_version' => SOAP_1_2));
$server->setClass("service");
$server->handle();
?>



serviceclient.php

<?php
try {
$client=new SoapClient("http://localhost/soapService/TestSoap.wsdl");
echo $client->HelloWorld();
echo("<br />");
print_r($client->Add(1,2));
}
catch ( SoapFault $e ) { echo $e->getMessage (); }
catch ( Exception $e ) { echo $e->getMessage (); }
?>


TestSoap.wsdl

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

<xsd:element name="out" type="xsd:string"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="AddRequest">
<wsdl:part name="a" type="xsd:int"/>
<wsdl:part name="b" type="xsd:int"></wsdl:part>
</wsdl:message>
<wsdl:message name="AddResponse">
<wsdl:part name="AddReturn" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="HelloWorldRequest">

</wsdl:message>
<wsdl:message name="HelloWorldResponse">
<wsdl:part name="HelloWorldReturn" type="xsd:string"></wsdl:part>
</wsdl:message>
<wsdl:portType name="TestSoap">
<wsdl:operation name="Add">
<wsdl:input message="tns:AddRequest"/>
<wsdl:output message="tns:AddResponse"/>
</wsdl:operation>
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldRequest"></wsdl:input>
<wsdl:output message="tns:HelloWorldResponse"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestSoapSOAP" type="tns:TestSoap">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Add">
<soap:operation soapAction="http://localhost/soapService/Add"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>

<wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://localhost/soapService/HelloWorld" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>

</wsdl:binding>

<wsdl:service name="TestSoap">
<wsdl:port binding="tns:TestSoapSOAP" name="TestSoapSOAP">
<soap:address location="http://localhost/soapService/soapserver.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>



在IE浏览器输入: http://localhost/soapService/serviceclient.php 显示以下

Hello
Procedure 'a' not present

第一个方法能正确输出字符。第二个方法就报错。Procedure 'a' not present

请各位老师指教。
...全文
131 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序猿之殇 2012-12-13
  • 打赏
  • 举报
回复
有时候可能是是缓存的问题。 如果是linux下,可以删除/tmp/wsdl-*的临时文件试试~
xuzuning 2012-12-13
  • 打赏
  • 举报
回复
输出 Hello 3 没有错误呀! 你的php版本是多少? 我的是5.3.6

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧