11

您好,我正在为 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();
?>

一个帮助...

  • 1个
    那么,您是否要求 WSDL 服务执行任何操作?或者只是在浏览器中访问它?它所做的只是告诉您没有可提供的网页,但是如果您向它发送一些它期望的 SOAP,也许它会起作用……  2012 年 2 月 3 日 14:29
  • 我只想显示我的 server.php 文件中的 xml 
    – h_a86
     2012 年 2 月 3 日 14:32

3 个回答  正确答案 

18

请将您的代码更改为,

<?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();
?>

你没有定义命名空间..

请在此处查看简单示例:-

http://patelmilap.wordpress.com/2011/09/01/soap-simple-object-access-protocol/

5个

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);

这应该显示Hello, StackOverFlow

更新

要创建 WSDL,您需要添加以下内容:

$server->configureWSDL(<webservicename>, <namespace>);
5个

您还可以使用 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)
?>

你的答案


来自  https://stackoverflow.com/questions/9130117/nusoap-simple-server



Soap(简单对象访问协议)

Soap 是非常简单的协议规范,用于在 Web 服务的实现中交换结构化信息。
它的消息格式依赖于 XML(可扩展标记语言)。
要在 Windows 服务器上启用 SOAP,请打开 php.ini 文件,找到“soap”并启用名为“extension=php_soap.dll”的扩展,我的意思是,删除“;” 在该语句之前,保存文件,重新启动 WAMP 服务器,你就完成了,SOAP 现在已启用,你可以检查你的 phpinfo()。
SOAP 提供了一种在不同操作系统、不同技术和编程语言上运行的应用程序之间进行通信的方法。

在这里,我将描述如何将 SOAP 与 PHP 一起使用。

下载最新的 nusoap.php 文件
创建一个名为 soap_server.php 的服务器文件

1个
2个
3个
4个
5个
6个
7
8个
9
10
11
12
13
14
15
<?php
require_once("nusoap.php");
$server = new soap_server();
$server->configureWSDL("TestingWSDL","urn:TestingWSDL");
 
$server->register("gethelloworld",array("name" => "xsd:string"),array("return" => "xsd:string"),"urn:helloworld","urn:helloworld#gethelloworld");
 
function gethelloworld($name) {
$myname    =    "My Name Is <b>".$name . "</b>";
return $myname;
}
 
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

3.创建一个名为helloworld.php的客户端文件

1个
2个
3个
4个
5个
6个
7
8个
<?php
include("nusoap.php");
$client = new soapclient("http://localhost/soap/soap_server.php?wsdl");
$result    =    $client->gethelloworld("Milap Patel");
echo "<pre>";
print_r($result);
echo "</pre>";
?>


来自  https://patelmilap.wordpress.com/2011/09/01/soap-simple-object-access-protocol/