Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Swift解析iOS中包含complextype的SOAP响应?_Php_Ios_Swift_Web Services_Soap - Fatal编程技术网

Php 如何使用Swift解析iOS中包含complextype的SOAP响应?

Php 如何使用Swift解析iOS中包含complextype的SOAP响应?,php,ios,swift,web-services,soap,Php,Ios,Swift,Web Services,Soap,我使用NuSOAP库用PHP编写这个soap web服务 require_once "nusoap/lib/nusoap.php"; $userBookServer = new nusoap_server(); $userBookServer->configureWSDL('recuperaLibri', 'urn:retrieveBooks'); $userBookServer->soap_defencoding = 'utf-8'; $userBookServer->w

我使用NuSOAP库用PHP编写这个soap web服务

require_once "nusoap/lib/nusoap.php";

$userBookServer = new nusoap_server();
$userBookServer->configureWSDL('recuperaLibri', 'urn:retrieveBooks');
$userBookServer->soap_defencoding = 'utf-8';

$userBookServer->wsdl->addComplexType(
    'Book',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'Titolo' => array('name' => 'Titolo', 'type' => 'xsd:string'),
        'Autore'=> array('name' => 'Autore', 'type' => 'xsd:string')
    )

);

$userBookServer->wsdl->addComplexType(
    'userBook',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
        array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Book[]')
    ),
    'tns:Book'
);

$userBookServer->register("recuperaLibri", array('id_unico' => 'xsd:string'),
    array('return' => 'tns:userBook'),'urn:recuperaLibri', 'urn:retrieveBooks#recuperaLibri','rpc','encoded');


/**
 * @param $uid
 */

function recuperaLibri($uid){

    require_once "DataStorage_utilities/DataManager.php";

    $response = array();
    //$response['userBook'] = array();

    $db = new DataManager();
    $userBooks = $db->getUserBook($uid);

    while($userBook = $userBooks->fetch_assoc()){

        //crea un array temporaneo
        $tmp = array();

        $tmp[0]['Titolo'] = $userBook[0]['Titolo'];
        $tmp[0]['Autore'] = $userBook[0]['Autore'];

        //inserisce l'array temporaneo nell'array response
        //array_push($response['userBook'], $tmp);
        array_push($response, $tmp);

    }

    //return json_encode($response);
    return $response;

}

$userBookServer->service(file_get_contents('php://input'));
exit();
函数
Recuroperalibri
返回一个包含用户书籍的数组。此数组必须显示在UITableView中。大概是这样的:

这是SOAP响应:

<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/" xmlns:tns="urn:retrieveBooks">    
<SOAP-ENV:Body>
  <ns1:recuperaLibriResponse xmlns:ns1="urn:recuperaLibri">
     <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:Book[0]"/>
  </ns1:recuperaLibriResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如何从SOAP响应中获取数组并正确显示它???

SOAP.envelope必须只包含附加名称空间,如下所示:

soap.envelope = "xmlns:com1='http://www.rbm.com.co/esb/comercio/'"

当使用名为requestWSDL的方法时,这不是优化的,速度非常慢,相反,您可以使用此处描述的优化:

您可能需要使用运行服务的机器的IP地址,而不是本地主机。此上下文中的Localhost是iPhone。此服务在Localhost中运行,而不是在其他计算机中运行。是的,但您的iPhone或模拟器是另一台计算机。如果您使用localhost,它将假定该服务正在iPhone上运行。您的服务是否在iPhone上运行?不,此服务在Apache中运行,在模拟器中不运行。请使用Apache服务器的IP地址,您将发现:D
2017-02-08 22:49:30.421 StudentPORT[2818:382651] Initializing SOAPEngine v.1.31
2017-02-08 22:49:30.517 StudentPORT[2818:382651] SOAPEngine Server response: (null)
Optional(Error Domain=NSOSStatusErrorDomain Code=0 "(null)")
soap.envelope = "xmlns:com1='http://www.rbm.com.co/esb/comercio/'"