2010-11-20 4 views
0

Salut, je suis en utilisant webservice et mon code i suivantmessage de réponse modifier dans nusoap

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

?> 

il génère la réponse comme

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

plutôt qu'au-dessus d'un je veux ce type de réponse comme

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

comment il possible plz aide

merci à l'avance

Répondre

1

Essayez la mise en place d'un tableau associatif pour votre réponse:

$response = array(); 
$response['status'] = array(); 
$response['status']['code'] = 'RW1'; 
$response['status']['message'] = 'Registration Warning nick exists'; 

return $response; 
Questions connexes