繁体   English   中英

PHP NuSOAP响应

[英]PHP NuSOAP response

nusoap服务器的响应像这样正常吗?

如果没有,我如何解决或删除&lt&gt并将其设为<>

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

这是我的返回函数

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

return $xmlDoc->saveXML($node);

从这个Nusoap使用现有的WSDL怎么做?

我找到了这个

var $methodreturnisliteralxml = false;

并在创建nusoap服务器时将其设置为true

$this->server->methodreturnisliteralxml = true;
array('return' => 'xsd:string')

输出是一个字符串 ,而不是xml-structure。 XML内的字符串必须进行编码。 如果要返回其他数据,则必须使用ComplexType 看这个问题: PHP Web Service NuSOAP复杂类型

例:

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


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

就像@butching所说的,您也会遇到编码不匹配的问题,这很糟糕,但不是导致问题的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM