PHP NuSOAP response

吃可爱长大的小学妹 提交于 2019-12-24 23:25:47

问题


Is it normal that the response of the nusoap server is like this?

If not, how do i fix or remove the &lt and &gt and make it as < and >

<?xml version="1.0" encoding="utf-8"?>
<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><ns1:get_stocksResponse xmlns:ns1="VSR"><return xsi:type="xsd:string">&lt;facilitator&gt;
&lt;stock_response&gt;
    &lt;product&gt;
      &lt;productid&gt;1072722&lt;/productid&gt;
      &lt;voorraad&gt;888040&lt;/voorraad&gt;
    &lt;/product&gt;
    &lt;product&gt;
      &lt;productid&gt;1072724&lt;/productid&gt;
      &lt;voorraad&gt;888603&lt;/voorraad&gt;
    &lt;/product&gt;
&lt;/stock_response&gt;
&lt;/facilitator&gt;
</return></ns1:get_stocksResponse></SOAP-ENV:Body></SOAP-ENV:Envelope></code>

this is my register function in the server

$this->server->register('get_stocks',                // method name
        array('product' => 'xsd:int'),        // input parameters
        array('return' => 'xsd:string'),      // output parameters
        $this->_namespace,                      // namespace
        'urn:'.$this->_namespace.'#get_stocks',                // soapaction
        'rpc',                                // style
        'encoded',                            // use
        'Get stocks of products'            // documentation
    ); 

and this is my return function

$xmlDoc = new DOMDocument('1.0', 'utf-8');
$xmlDoc->formatOutput = TRUE;
...etc
$nodes = $xmlDoc -> getElementsByTagName ('facilitator');
$node = $nodes -> item(0);

return $xmlDoc->saveXML($node);

回答1:


from this Nusoap use existing WSDL how to?

i found this

var $methodreturnisliteralxml = false;

and just set it to true upon creating the nusoap server

$this->server->methodreturnisliteralxml = true;



回答2:


array('return' => 'xsd:string')

the output is a string, not xml-structure. Strings inside XML must be encoded. If you want to return other data you have to use a ComplexType. Look at this question: PHP Web Service NuSOAP complex type

Example:

$this->server->wsdl->addComplexType(/** definition **/);


$this->server->register('get_stocks',              // method name
    array('product' => 'xsd:int'),                 // input parameters
    array('return' => 'tns:yourComplexType'),      // output parameters

Like @butching said, you also have an encoding mismatch, which is bad but not the cause for your issue.



来源:https://stackoverflow.com/questions/23867128/php-nusoap-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!