php nusoap 简单服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9130117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nusoap simple server
提问by h_a86
Hi i am using this code for nusoap server but when i call the server in web browser it shows message "This service does not provide a Web description" Here is the code
嗨,我将此代码用于 nusoap 服务器,但是当我在 Web 浏览器中调用服务器时,它显示消息“此服务不提供 Web 描述”这是代码
<?
//call library
require_once ('lib/nusoap.php');
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('hello');
// create the function
function hello($name)
{
if(!$name){
return new soap_fault('Client','','Put your name!');
}
$result = "Hello, ".$name;
return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
An help ...
一个帮助...
回答by Milap
Please change your code to,
请将您的代码更改为,
<?php
//call library
require_once('nusoap.php');
$URL = "www.test.com";
$namespace = $URL . '?wsdl';
//using soap_server to create server object
$server = new soap_server;
$server->configureWSDL('hellotesting', $namespace);
//register a function that works on server
$server->register('hello');
// create the function
function hello($name)
{
if (!$name) {
return new soap_fault('Client', '', 'Put your name!');
}
$result = "Hello, " . $name;
return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
You didnt Define namespace..
你没有定义命名空间..
Please see simple example here :-
请在此处查看简单示例:-
http://patelmilap.wordpress.com/2011/09/01/soap-simple-object-access-protocol/
http://patelmilap.wordpress.com/2011/09/01/soap-simple-object-access-protocol/
回答by Manse
The web browser is not calling the Web service - you could create a PHP client :
Web 浏览器没有调用 Web 服务 - 您可以创建一个 PHP 客户端:
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new soapclient('your server url');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'StackOverFlow'));
// Display the result
print_r($result);
This should display Hello, StackOverFlow
这应该显示 Hello, StackOverFlow
Update
更新
To create a WSDL you need to add the following :
要创建 WSDL,您需要添加以下内容:
$server->configureWSDL(<webservicename>, <namespace>);
回答by Brian Kenya
You can also use nusoap_client
你也可以使用 nusoap_client
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('your server url'); // using nosoap_client
// Call the SOAP method
$result = $client->call('hello', array('name' => 'Pingu'));
// Display the result
print_r($result)
?>