修改NUSOAP中的响应消息

发布于 2024-10-03 10:47:09 字数 3694 浏览 1 评论 0原文

您好,我正在使用网络服务,我的代码

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

所以怎么可能,请帮忙

提前致谢

hi i am using webservice and my code i following

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

?>

it generate the response like

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

instead of above one i wanna this type of response like

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

so how it possible plz help

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦浮鱼 2024-10-10 10:47:09

尝试为您的响应设置关联数组:

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

return $response;

Try setting up an associative array for your response:

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

return $response;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文