新装的系统,apache根目录在/var/www/html下,
phpclient.php代码:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$soap = new SoapClient("http://localhost/soap.wsdl");
var_dump ( $soap->__getFunctions () );echo $soap->Add(1,2);?>
soap.php代码:
<?php
class service
{
  public function HelloWorld()
   {
      return  "Hello";
   }
  public  function Add($a,$b)
   {
      return $a+$b;
   }
}
$server=new SoapServer("http://localhost/soap.wsdl",array('soap_version' => SOAP_1_2));
$server->setClass("service");
$server->handle();
?>
soap.wsdl代码:
<?xml version="1.0" ?>
<definitions name="myservice" targetNamespace="urn:myservice" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:myservice" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types xmlns="http://schemas.xmlsoap.org/wsdl/" />
<portType name="myservicePort"><operation name="HelloWorld">
<input message="tns:HelloWorldRequest" />
<output message="tns:HelloWorldResponse" />
</operation>
<operation name="Add">
<input message="tns:AddRequest" />
<output message="tns:AddResponse" />
</operation>
</portType>
<binding name="myserviceBinding" type="tns:myservicePort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="HelloWorld">
<soap:operation soapAction="urn:myservice#service#HelloWorld" />
<input><soap:body use="encoded" namespace="urn:myservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:myservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
<operation name="Add">
<soap:operation soapAction="urn:myservice#service#Add" />
<input><soap:body use="encoded" namespace="urn:myservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:myservice" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="myservice">
<documentation />
<port name="myservicePort" binding="tns:myserviceBinding"><soap:address location="http://localhost:80/phpsoap/soap.php" />
</port>
</service>
<message name="HelloWorldRequest">
</message>
<message name="HelloWorldResponse">
<part name="HelloWorld" type="xsd:string" />
</message>
<message name="AddRequest">
<part name="a" type="xsd:string" />
<part name="b" type="xsd:string" />
</message>
<message name="AddResponse">
<part name="Add" type="xsd:string" />
</message>
</definitions>
一开赛的时候我是把soap.wsdl放在/var/www/html/wsdl文件夹里面的,原来的"http://localhost/soap.wsdl"为"http://localhost/wsdl/soap.wsdl" 可是不知道为什么报:Fatal error: Uncaught SoapFault exception: [HTTP] Not Found in的错误,路径是没错的呀?

解决方案 »

  1.   

    你是一点概念都未有啊wsdl 不是可调用的文件,况且你开启了段标记
    <?xml 不能被 php 所接受wsdl 只是 soap 的参数文件,并与 soap 主程序同主文件名调用时应为
    phpclient.php代码:
    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    $soap = new SoapClient("http://localhost/soap.php?wsdl