Nusoap-修复响应的空xmlns属性 [英] Nusoap - fix empty xmlns attribute for the response

查看:138
本文介绍了Nusoap-修复响应的空xmlns属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Php Nusoap创建了一个简单的Web服务.它可以正常工作,但是唯一缺少的是将默认的xmlns属性添加到响应标签.
这是Response的副本:

 <?  xml    版本  ="    编码  ="  ISO-8859-1" > 
<   SOAP-ENV:信封    SOAP-ENV:encodingStyle   ="    xmlns:SOAP-ENV   ="     xmlns:xsd   ="    xmlns:xsi   ="   xmlns:SOAP-ENC    http://schemas.xmlsoap.org/soap/encoding/" <   SOAP-ENV:Body  > 
    <   LoginResponse     ="  " > 
      <   LoginResult  > 
        <  注册 > 
          <  客户 >  d2ff3b88d34705e01d150c21fa7bde07 <  /customer  > 
        <  /register  > 
      <  /LoginResult  > 
    <  /LoginResponse  > 
  <  /SOAP-ENV:Body  > 
<  /SOAP-ENV:Envelope  >  


这是代码:

<?php
require_once (''nusoap.php'');
// set namespace
$ns = ''mynamspace'';
// set up soap server
$server = new soap_server ();
$server->configureWSDL ( ''testservice'', $ns);
$server->wsdl->schemaTargetNamespace = $ns;
// define new user data type

// define results

$server->wsdl->addComplexType ( ''customer'', ''complexType'', ''struct'', '''', '''', array (''customer'' => array (''name'' => ''customer'', ''type'' => ''xsd:string'' ) ) );
$server->wsdl->addComplexType ( ''register'', ''complexType'', ''struct'', '''', '''', array (''register'' => array (''name'' => ''register'', ''type'' => ''tns:customer'' ) ) );
$server->wsdl->addComplexType ( ''LoginResult'', ''complexType'', ''struct'', '''', '''', array (''LoginResult'' => array (''name'' => ''LoginResult'', ''type'' => ''tns:register'' ) ) );
// register Login function
$server->register ( ''Login'', // method name
array (''username'' => ''xsd:string'', ''password'' => ''xsd:string'' ), // input parameters
array (''LoginResult'' => ''tns:register'' ), // output parameters
''urn:mynamespace'', // namespace
''urn:mynamespaceAction'', // soapaction
''document'', // style
''literal'', // use
''Login service for testing'' ); // documentation

function Login($username, $password) {
    if (isset ( $username ) && isset ( $password )) {
        $hash = md5 ( $username );
        return array (''LoginResult'' => array (''register'' => array (''customer'' => $hash ) ));
    }
}
// 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 );
?>


解决方案

ns ="mynamspace"; //设置肥皂服务器


server = new soap_server();


server-> configureWSDL(``testservice'',

Hi, I have created a simple web service using Php Nusoap. It''s working correctly but the only thing missing is to add the default xmlns attribute to the response tag.
Here is the copy of Response :

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <LoginResponse xmlns="">
      <LoginResult>
        <register>
          <customer>d2ff3b88d34705e01d150c21fa7bde07</customer>
        </register>
      </LoginResult>
    </LoginResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Here is the code :

<?php
require_once (''nusoap.php'');
// set namespace
$ns = ''mynamspace'';
// set up soap server
$server = new soap_server ();
$server->configureWSDL ( ''testservice'', $ns);
$server->wsdl->schemaTargetNamespace = $ns;
// define new user data type

// define results

$server->wsdl->addComplexType ( ''customer'', ''complexType'', ''struct'', '''', '''', array (''customer'' => array (''name'' => ''customer'', ''type'' => ''xsd:string'' ) ) );
$server->wsdl->addComplexType ( ''register'', ''complexType'', ''struct'', '''', '''', array (''register'' => array (''name'' => ''register'', ''type'' => ''tns:customer'' ) ) );
$server->wsdl->addComplexType ( ''LoginResult'', ''complexType'', ''struct'', '''', '''', array (''LoginResult'' => array (''name'' => ''LoginResult'', ''type'' => ''tns:register'' ) ) );
// register Login function
$server->register ( ''Login'', // method name
array (''username'' => ''xsd:string'', ''password'' => ''xsd:string'' ), // input parameters
array (''LoginResult'' => ''tns:register'' ), // output parameters
''urn:mynamespace'', // namespace
''urn:mynamespaceAction'', // soapaction
''document'', // style
''literal'', // use
''Login service for testing'' ); // documentation

function Login($username, $password) {
    if (isset ( $username ) && isset ( $password )) {
        $hash = md5 ( $username );
        return array (''LoginResult'' => array (''register'' => array (''customer'' => $hash ) ));
    }
}
// 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 );
?>


Any help is greatly appreciated.

解决方案

ns = ''mynamspace''; // set up soap server


server = new soap_server ();


server->configureWSDL ( ''testservice'',


这篇关于Nusoap-修复响应的空xmlns属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆