Привет, вопрос по теме SOAP.
Soap установлен как модуль Apache.
Стоит задача, вернуть c сервера данные в виде массива объектов типа stdClass.
Ниже приведу код WSDL файла и код сервера...
Если возвращаю обычный массив, то мой клиент на сервере все прекрасно понимает... а клиент на платформе 1С завершается неудачей при чтении возвращаемых данных.
Покумекав я решил, раз сервер при запросе от 1С получает массив объектов, то и возвращать нужно так же массив объектов.
Но не получается организовать возвращение многомерного массива объектов
Подскажите как описать WSDL файл?
Файл WSDL
CODE ( htmlphp):
скопировать код в буфер обмена
<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:
скопировать код в буфер обмена
<?PHP class PriceService { function getArrayPrice($parts) { //преобразуем объект в массив $array = $this->objectToArray($parts); foreach($array['parts'] as $v) { $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); return $objArray; } //------------------------------------------------------------------ //Запрос авторизации function auth($pass){ $r = mysql_qw("SELECT `password` FROM `modx_web_users` WHERE id=?", $pass); 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); return (float)$row['price']; } //------------------------------------------------------------------ /** * Преобразование объекта в массив * @param object $object преобразуемый объект * @reeturn array */ function objectToArray($object) { return $object; } //------------------------------------------------------------------ /** * Преобразование массива в объект * @param array $array преобразуемый массив * @reeturn object */ function arrayToObject ($array = 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(); ?>
(Отредактировано автором: 13 Июня, 2013 - 21:40:52)
|