您好我正在使用webservice和我的代码
<?php
// Pull in the NuSOAP code
require_once('nusoap/nusoap.php');
require_once('common.php');
header('Content-Type: text/xml; charset=utf8');
// Create the server instance
$server = new nusoap_server();
$server->xml_encoding = "utf-8";
$server->soap_defencoding = "utf-8";
//$server->decode_utf8 = false;
// Initialize WSDL support
$server->configureWSDL('hellowsdl2', 'urn:hellowsdl2');
$host="localhost";
$user="root";
$password="root";
/*$host="localhost";
$user="phpteam";
$password="phpteam";
*/
$dbname="fanticker";
$con = mysql_connect($host,$user,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);
// Register the method to expose
/*insert user function*/
$server->register(
'insertUser',
array('password'=>'xsd:string','email'=>'xsd:string','status'=>'xsd:string','nickname'=>'xsd:string','deviceserial'=>'xsd:string','devicename'=>'xsd:string','devicetype'=>'xsd:string'),
array('return'=>'xsd:string'),
'urn:hellowsdl', // namespace
'urn:hellowsdl#hello', // soapaction
'rpc', // style
'encoded', // use
'Says hello world to client' // documentation
);
/**
* @param $uname
* @param $password
* @param $email
* @param $status
* @param $nick
* @param $deviceserial
* @param $devicename
* @param $devicetype
* @param $credits
* @param $last_league_id
* @param $last_match_ticker_mat_id
* @param $lastmatchid
* @param $usr_preferences
* @return string
*/
function insertUser($password,$email,$status,$nickname,$deviceserial,$devicename,$devicetype)
{
$nick_check=check_nick_exists($nickname);
$email_check=check_email_exists($email);
if($nick_check==true)
{
return "RW1-Registration Warning Nick Exists";
}
if(!isValidEmail($email))
{
return "RW3-Registration Warning Email Format";
}
if($email_check==true)
{
return "RW2-Registration Warning Email Exists";
}
if(!isValidPassword($password))
{
return "RW4-Registration Warning Password Incorrect";
}
$qry="INSERT INTO usr_user (USR_password ,USR_email ,USR_status ,USR_nick ,USR_device_serial ,USR_device_name ,USR_device_type ,USR_last_league_LGT_id ,USR_last_match_ticker_MAT_id ,USR_last_match_reporting_MAT_id ,USR_Preferences)VALUES ('".$password."','".$email."','".$status."','".$nickname."','".$deviceserial."','".$devicename."','".$devicetype."')";
$query = mysql_query($qry);
if($query==true)
{
return "User Inserted";
}
else
{
return "some field missing";
}
}
//function for check exist data
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
它生成响应,如
-<SOAP-ENV:Body>
-<ns1:insertUserResponse xmlns:ns1="urn:hellowsdl2">
-<return xsi:type="xsd:string">RW1-Registration Warning Nick Exists</return>
</ns1:insertUserResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
而不是一个我希望这种类型的回应,如
-<SOAP-ENV:Body>
-<ns1:insertUserResponse xmlns:ns1="urn:hellowsdl2">
<status>
<code>RW1</code>
<message>registration warning nick exists</message>
<status>
</ns1:insertUserResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
所以怎么可能plz帮助
提前致谢
答案 0 :(得分:1)
尝试为您的回复设置关联数组:
$response = array();
$response['status'] = array();
$response['status']['code'] = 'RW1';
$response['status']['message'] = 'Registration Warning nick exists';
return $response;