John Davidson

php - SOAP Webservice - error on line 2 at column 1: Extra content at the end of the document

0 comments
Message:


I'm trying to create a user-defined SOAP Webservice using nusoap with the following codes:


service.php


<?php
require 'nusoap/lib/nusoap.php';
require 'fetchdata.php';

$server = new nusoap_server();
$server->configureWSDL("Book Info Service","urn:soaptest");
$server->register(
"get_info",
array("input"=>"xsd:string"),
array("return"=>"xsd:string")
);


$server->service(file_get_contents("php://input"));

?>

fetchdata.php


<?php

function get_info($input)
{
$books = [
"9780435910105"=>["Opening Spaces: An Anthology of Contemporary African Women's Writing","Yvonne Vera","Heinemann"],
"9780394721170"=>["African Folktales","Roger D. Abrahams","Knopf Doubleday Publishing Group"],
"9781558615007"=>["Women Writing Africa: West Africa and the Sahel","Esi Sutherland-Addy","Feminist Press at CUNY"]
];

foreach($books as $isbn=>$info)
{
if($isbn==$input)
{
return "<b>Title:</b> ".$info[0]."<br /><br /><b>Author:</b> ".$info[1]."<br /><br /><b>Publisher:</b> ".$info[2];
break;
}

}
return "No information found for"." ".$input;
}

?>

When I run it locally, the WSDL page throws an error and the rest of the page is blank



This page contains the following errors:


error on line 2 at column 1: Extra content at the end of the document


Below is a rendering of the page up to the first error.



Why is this happening?
I want to integrate this into an app so I need the WSDL link.


I honestly just copied and modified this so I don't really know what is happening.
Can anyone help? Thank you.



My Answer:
php
require_once('lib/nusoap.php');

$server = new soap_server();
$server->configureWSDL('UserWebService', 'urn:UserWebService');

$server->register('getUserInfo',
array('username' => 'xsd:string'),
array('return' => 'xsd:string'),
'urn:UserWebService',
'urn:UserWebService#getUserInfo',
'rpc',
'encoded',
'Get user information by username');

function getUserInfo($username) {
// Code to fetch user information from database
return "User information for ".$username;
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>


_client.php_

php
require_once('lib/nusoap.php');

$client = new soapclient('http://localhost/service.php?wsdl', true);

$username = 'john_doe';
$response = $client->call('getUserInfo', array('username' => $username));

echo $response;
?>


Make sure that you have the `nusoap.php` file in the `lib` directory and that your server is running PHP with SOAP extension enabled. Also, ensure that the WSDL file is accessible at `http://localhost/service.php?wsdl`.

Rate this post

5 of 5 based on 4643 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us