[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Soap - возвратить многомерный массив объектов
rudiwork
Привет, вопрос по теме SOAP.
Soap установлен как модуль Apache.
Стоит задача, вернуть c сервера данные в виде массива объектов типа stdClass.
Ниже приведу код WSDL файла и код сервера...
Если возвращаю обычный массив, то мой клиент на сервере все прекрасно понимает... а клиент на платформе 1С завершается неудачей при чтении возвращаемых данных.
Покумекав я решил, раз сервер при запросе от 1С получает массив объектов, то и возвращать нужно так же массив объектов.
Но не получается организовать возвращение многомерного массива объектов
Подскажите как описать WSDL файл?
Файл WSDL

<<definitions 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:europarts" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:europarts">
<types>
<xsd:schema
targetNamespace="urn:europarts">
<xsd:import
namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import
namespace="http://schemas.xmlsoap.org/wsdl/"/>
<xsd:complexType
name="ItemPart">
<xsd:sequence>
<xsd:element
name="number" type="xsd:string"/>
<xsd:element
name="priority" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType
name="ArrayOfItemPart">
<xsd:sequence>
<xsd:element
name="password" type="xsd:string"/>
<xsd:element
name="parts" type="tns:ItemPart" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType
name="ItemPartPrice">
<xsd:sequence>
<xsd:element
name="number" type="xsd:string"/>
<xsd:element
name="priority" type="xsd:int"/>
<xsd:element
name="price" type="xsd:float"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType
name="ArrayOfItemPartPrice">
<xsd:sequence>
<xsd:element
name="result" type="tns:ItemPartPrice" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</types>
<message
name="getArrayPriceRequest">
<part
name="array" type="tns:ArrayOfItemPart"/>
</message>
<message
name="getArrayPriceResponse">
<part
name="array" type="tns:ArrayOfItemPartPrice"/>
</message>
<portType
name="europartsPortType">
<operation
name="getArrayPrice">
<documentation>
get array price</documentation>
<input
message="tns:getArrayPriceRequest"/>
<output
message="tns:getArrayPriceResponse"/>
</operation>
</portType>
<binding
name="europartsBinding" type="tns:europartsPortType">
<soap:binding
style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation
name="getArrayPrice">
<soap:operation
soapAction="urn:europarts#getArrayPrice" style="rpc"/>
<input>
<soap:body
use="encoded" namespace="urn:europarts" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body
use="encoded" namespace="urn:europarts" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service
name="europarts">
<port
name="europartsPort" binding="tns:europartsBinding">
<soap:address
location="http://europarts.pro/webservicePrice/server.php"/>
</port>
</service>
</definitions>



Сервер

<?php
class
PriceService {
function getArrayPrice($parts) {
//преобразуем объект в массив
$array = $this->objectToArray($parts);

$fp = fopen("loggg.txt", "w");
fprintf($fp, "%s", serialize($array));
fclose($fp);

//Проверка авторизации
//if(!$this->auth($array['password'])) return array();


$result = array();
foreach($array['parts'] as $v) {
$tmp = array();
$tmp['number'] = $v['number'];
$tmp['priority'] = $v['priority'];
$tmp['price'] = $this->getPartPrice($v['number'], $v['priority']);
$result['result'][] = $tmp;
}

//Преобразуем массив в объект
$objArray = object;
$objArray = $this->arrayToObject($result);

$fp = fopen("log_return.txt", "w");
fprintf($fp, "%s", serialize($result));
fclose($fp);

return $result;
}
//------------------------------------------------------------------
//Запрос авторизации

function auth($pass){
$r = mysql_qw("SELECT `password` FROM `modx_web_users` WHERE id=?", $pass);
$row = mysql_fetch_assoc($r);
if(md5($pass) !== $row['password'])
return false;
return true;
}
//------------------------------------------------------------------
//Полцчить цену на товар

function getPartPrice($number, $priority) {
$r = mysql_qw("SELECT `price` FROM `modx_catalog` WHERE `number`=? AND `priority`=?", $number, $priority);
if(mysql_num_rows($r) < 1) return 0;
$row = mysql_fetch_assoc($r);
return (float)$row['price'];
}
//------------------------------------------------------------------
/**
* Преобразование объекта в массив
*
@param object $object преобразуемый объект
*
@reeturn array
*/

function objectToArray($object) {
if(!is_object($object) && !is_array($object))
return $object;
if(is_object($object))
$object = get_object_vars($object);
return array_map(array($this, 'objectToArray'), $object );
}
//------------------------------------------------------------------
/**
* Преобразование массива в объект
*
@param array $array преобразуемый массив
*
@reeturn object
*/

function arrayToObject($array = array()) {
if (!empty($array)) {
$data = false;
foreach ($array as $akey => $aval) {
//$data -> {$akey} = $aval;
$data ->{$akey} = is_array($aval) ? $this->arrayToObject($aval) : $aval;
}
return $data;
}
return false;
}
//------------------------------------------------------------------
}

ini_set("soap.wsdl_cache_enabled", "0"); // отключаем кэширование WSDL
$server = new SoapServer("price.wsdl");
$server->setClass("PriceService");
$server->handle();
?>
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.