Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php上创建web服务_Php_Web Services_Web - Fatal编程技术网

在php上创建web服务

在php上创建web服务,php,web-services,web,Php,Web Services,Web,我正在尝试创建一个web服务,但我无法理解这里的问题是什么 SimpleClient.php <?php include_once("nusoap.php"); try { // Create a soap client using SoapClient class // Set the first parameter as null, because we are operating in non-WSDL mode. // Pass array containing url an

我正在尝试创建一个web服务,但我无法理解这里的问题是什么

SimpleClient.php

 <?php
include_once("nusoap.php");

try {

// Create a soap client using SoapClient class
// Set the first parameter as null, because we are operating in non-WSDL mode.
// Pass array containing url and uri of the soap server as second parameter.
$client = new SoapClient(null, array(
'location' => "http://www.example.com/SimpleServer.php",
'uri' => "http://www.example.com"));
// Read request parameter
$param = $_POST['name'];
// Invoke AddHello() method of the soap server (HelloServer)
$result = $client->AddHello($param);
echo $result; // Process the the result
echo "test";
}
catch(SoapFault $ex) {
$ex->getMessage();
echo 'test';
}
?>

SimpleServer.php

    <?php
include_once("nusoap.php");

// Simple Method get 1 parameter and return with Hello
function AddHello($name)
{
     return "Hello $name";
}
// Create SoapServer object using WSDL file.
// For the simplicity, our SoapServer is set to operate in non-WSDL mode. So we do not need a WSDL file
$server = new SoapServer(null, array('uri'=>'http://www.example.com'));
// Add AddHello() function to the SoapServer using addFunction().
$server->addFunction("AddHello");
// To process the request, call handle() method of SoapServer.
$server->handle();
?> 

SimpleView.php

  <?php
echo "<h2>Welcome to PHP Web Service</h2>";
echo "<form action='SimpleClient.php' method='POST'/>";
echo "<input name='name' /><br/>";
echo "<input type='Submit' name='submit' value='Send'/>";
echo "</form>";
?>

我查看了您参考的教程,它对我很有用
只需下载他们提供的代码并在中更改uri参数
SimpleClient.php文件

如果apache服务器托管在端口80之外,请正确指定该端口

我从那里下载了代码并粘贴到了webroot目录中 网络服务目录

因此SimpleClient.php与端口80类似

<?php
try {
// Create a soap client using SoapClient class
// Set the first parameter as null, because we are operating in non-WSDL mode.
// Pass array containing url and uri of the soap server as second parameter.
$client = new SoapClient(null, array(
'location' => "http://localhost/Web_Service/SimpleServer.php",
'uri' => "http://localhost/Web_Service/"));
// Read request parameter
$param = $_POST['name'];
// Invoke AddHello() method of the soap server (HelloServer)
$result = $client->AddHello($param);
echo $result; // Process the the result
}
catch(SoapFault $ex) {
$ex->getMessage();
}
?>

如果您的服务器托管在不同的端口中,请指定如下端口。 这里我提到了81端口

<?php
try {
// Create a soap client using SoapClient class
// Set the first parameter as null, because we are operating in non-WSDL mode.
// Pass array containing url and uri of the soap server as second parameter.
$client = new SoapClient(null, array(
'location' => "http://localhost:81/Web_Service/SimpleServer.php",
'uri' => "http://localhost:81/Web_Service/"));
// Read request parameter
$param = $_POST['name'];
// Invoke AddHello() method of the soap server (HelloServer)
$result = $client->AddHello($param);
echo $result; // Process the the result
}
catch(SoapFault $ex) {
$ex->getMessage();
}
?>

在SimpleServer中:在使用AddHello函数之前,您需要对其进行重新设置

$server->register('AddHello',$name)
有关web服务和解决问题的更多信息,请查看以下链接:

您是否关闭了PHP错误?如果您看到的是一个空白屏幕,这可能意味着PHP抛出了一个致命错误,但由于配置设置的原因,正在抑制该错误。打开错误消息,您将看到更多信息,以帮助您调试问题。(或者查看服务器日志文件,它将包含相同的信息)很抱歉,它的错误\u reporting=30711:Salso,我注意到您正在使用NuSoap库。您是否知道PHP有自己的内置Soap类,使NuSoap变得多余。请看,我在过去创建了一个库,它生成WSDL文档并处理入/出soap消息。这很简单,您可以查看以下URL: