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请各位老师指教。
<?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请各位老师指教。
Hello
3没有错误呀!你的php版本是多少?
我的是5.3.6
如果是linux下,可以删除/tmp/wsdl-*的临时文件试试~