2012-02-03 33 views
8

Hi tôi đang sử dụng mã này cho máy chủ nusoap nhưng khi tôi gọi máy chủ trong trình duyệt web nó cho thấy thông báo "Dịch vụ này không cung cấp một mô tả Web" Đây là mãnusoap đơn giản máy chủ

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

Một sự giúp đỡ ...

+1

Vâng, anh có yêu cầu dịch vụ WSDL để * làm * bất cứ điều gì? Hoặc chỉ cần truy cập nó trong một trình duyệt? Tất cả những gì bạn đang làm là nói với bạn rằng không có trang web nào để phục vụ, nhưng nếu bạn gửi một số SOAP mà nó mong đợi, có thể nó sẽ hoạt động ... – DaveRandom

+0

tôi chỉ muốn hiển thị xml từ tệp tin server.php của tôi –

Trả lời

15

Vui lòng thay đổi mã của bạn để,

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

Bạn didnt Xác định không gian tên ..

Vui lòng xem ví dụ đơn giản tại đây: -

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

4

Trình duyệt web không phải là cách gọi dịch vụ Web - bạn có thể tạo một client 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); 

này sẽ hiển thị Hello, StackOverFlow

Cập nhật

Để tạo WSDL bạn cần phải thêm những điều sau đây:

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

Bạn cũng có thể sử dụng 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) 
?> 
Các vấn đề liên quan