我正在学习如何使用c#和PHP创建web服务,c#正在工作,但PHP的一个给我一个错误:
第1行第2列错误:StartTag: invalid element name
当我点击wsdl时,PHP客户端没有返回任何东西我的代码是这样的:
服务器(PHPWebService.php):
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Web Service</title>
</head>
<body>
<?php
require "lib/nusoap.php";
function MyFunction($name){
return $name;
}
$server = new nusoap_server();
$server->configureWSDL("MyPHPWebService","urn:PHPWebService");
$server->register("MyFunction",array("name"=>"xsd:string"),array("return"=>"xsd:string"));
if(isset($HTTP_Raw_POST_DATA)){
$HTTP_Raw_POST_DATA = $HTTP_Raw_POST_DATA;
}else{
$HTTP_Raw_POST_DATA = "No Name!";
}
$server->service($HTTP_Raw_POST_DATA)
?>
</body>
</html>
客户端(PHPClient.php):
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Web Service Client</title>
</head>
<body>
<?php
require "lib/nusoap.php";
$client = new nusoap_client("http://localhost/PHPWebService/PHPWebService.php?wsdl");
$response = $client->call("name",array("name"=>"Emad Zedan"));
echo $response;
?>
</body>
</html>
您看到的错误是因为NuSOAP客户机试图读取您的服务器文件输出的HTML。
如果你从PHPWebService.php中删除所有的HTML(即所有不在<?php
?>
标签之间的内容),错误就会消失。