我是soap webservice的新手。我用php语言编写了一个服务器和一个客户端文件,我遇到了这个输出:看起来我们没有XML文档
soap_server.php:
<?php require_once ('lib/nusoap.php');
$namespace = "http://localhost/webservice/soap_server.php?wsdl";
$server = new soap_server();
$server->configureWSDL("webservice");
$server->wsdl->schemaTargetNamespace = $namespace;
//register a function that works on server
$server->register('get_message');
// create the function
function get_message($your_name)
{
if(!$your_name){
return new soap_fault('Client','','Put Your Name!');
//echo "no name"
}
$result = "Welcome to ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP";
return $result;
}
//create HTTP listener
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server ->service($HTTP_RAW_POST_DATA);
exit();
?>
soap_client.php:
<?php require_once ('lib/nusoap.php');
//Give it value at parameter
$param = array( 'your_name' => 'Monotosh Roy');
$url='http://localhost/webservice/soap_server.php?wsdl';
// echo file_get_contents($url);
//Create object that referer a web services
try
{
$client = new SoapClient($url);
//Call a function at server and send parameters too
$response = $client->get_message($param);
var_dump($response);
echo "ok";
}
catch(SoapFault $e)
{
echo "nok";
print_r($e);
}
http://localhost/webservice/soap_client.php的输出:
nokSoapFault Object
(
[message:protected] => looks like we got no XML document
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => C:\xampp\htdocs\webservice\soap_client.php
[line:protected] => 14
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => C:\xampp\htdocs\webservice\soap_client.php
[line] => 14
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => get_message
[1] => Array
(
[0] => Array
(
[your_name] => Monotosh Roy
)
)
)
)
[1] => Array
(
[file] => C:\xampp\htdocs\webservice\soap_client.php
[line] => 14
[function] => get_message
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => Array
(
[your_name] => Monotosh Roy
)
)
)
)
[previous:Exception:private] =>
[faultstring] => looks like we got no XML document
[faultcode] => Client
[faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
)
http://localhost/webservice/soap_server.php的输出:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://localhost/soap/webservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://localhost/soap/webservice">
<types>
<xsd:schema targetNamespace="http://localhost/soap/webservice">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
</xsd:schema>
</types>
<message name="get_messageRequest"/>
<message name="get_messageResponse"/>
<portType name="webservicePortType">
<operation name="get_message">
<input message="tns:get_messageRequest"/>
<output message="tns:get_messageResponse"/>
</operation>
</portType>
<binding name="webserviceBinding" type="tns:webservicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="get_message">
<soap:operation soapAction="http://localhost/webservice/soap_server.php/get_message" style="rpc"/>
<input>
<soap:body use="encoded" namespace="" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="webservice">
<port name="webservicePort" binding="tns:webserviceBinding">
<soap:address location="http://localhost/webservice/soap_server.php"/>
</port>
</service>
</definitions>