Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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
WSDL-PHP-Soapserver数组和复杂类型请求_Php_Arrays_Object_Wsdl_Soapserver - Fatal编程技术网

WSDL-PHP-Soapserver数组和复杂类型请求

WSDL-PHP-Soapserver数组和复杂类型请求,php,arrays,object,wsdl,soapserver,Php,Arrays,Object,Wsdl,Soapserver,我已经用php Soapserver在php中创建了一个soap服务器。我创建了一个函数“addItems”,将多个项作为数组添加到第一个参数和相应的wsdl文档中。在wsdl中,我创建了一个数组对象“items”,如下所示: <s:complexType name="items"> <s:sequence> <s:element nillable="true" name="item" type="tns:item" mi

我已经用php Soapserver在php中创建了一个soap服务器。我创建了一个函数“addItems”,将多个项作为数组添加到第一个参数和相应的wsdl文档中。在wsdl中,我创建了一个数组对象“items”,如下所示:

<s:complexType name="items"> 
        <s:sequence> 
            <s:element nillable="true" name="item" type="tns:item" minOccurs="0" maxOccurs="unbounded"/> 
        </s:sequence> 
     </s:complexType> 
<?php
class Test
{
     public function addItems($items) {
         print_r($items);
     }
}
$service = new Test();
$server = new SoapServer('wsdl.xml');
$server->setObject();
print($server->handle());  
$items参数的预期结果

    Array
    (
        [item] => Array
        (
             [id] => 1
             [name] => a
        )
    )
Array
    [0] => (
        Array
           (
                [id] => 1
                [name] => a
            )
    )
Array
(
    [item] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [name] => a
                )

            [1] => Array
                (
                    [id] => 2
                    [name] => b
                )

        )
)
请求具有多个:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:addItems" xmlns:wsdl="http://base.shopzonline.com/soap/api/test/?wsdl">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:addItems>
         <items>
            <!--Zero or more repetitions:-->
            <wsdl:item>
               <wsdl:id>1</wsdl:id>
               <wsdl:name>a</wsdl:name>
            </wsdl:item>

            <wsdl:item>
               <wsdl:id>2</wsdl:id>
               <wsdl:name>b</wsdl:name>
            </wsdl:item>          
         </items>
      </urn:addItems>
   </soapenv:Body>
</soapenv:Envelope>
预期结果

Array
(
    [0] => Array
        (
            [id] => 1
            [name] => a
        )

    [1] => Array
        (
            [id] => 2
            [name] => b
        )
)
在完整的WSDL下面:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions  name="LocalhostTestWebservice"
 targetNamespace="http://localhost/soap/api/test/?wsdl" 
 xmlns="http://schemas.xmlsoap.org/wsdl/"
 xmlns:tns="http://localhost/soap/api/test/?wsdl"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 xmlns:s="http://www.w3.org/2001/XMLSchema"
   >
   <wsdl:types>
      <s:schema elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="http://localhost/soap/api/test/?wsdl">
         <s:complexType name="addItemsResponseElement">
            <s:sequence>
               <s:element name="result" minOccurs="0" type="s:int"/>
            </s:sequence>
         </s:complexType>
         <s:element name="addItemsResponseElement" nillable="true" type="tns:addItemsResponseElement"  />
         <s:complexType name="item">
            <s:sequence>
               <s:element name="id" type="s:string" /> 
               <s:element name="name" type="s:string" /> 
            </s:sequence>
         </s:complexType>
         <s:element name="item" type="tns:item" />
         <s:complexType name="items"> 
            <s:sequence> 
                <s:element nillable="true" name="item" type="tns:item" minOccurs="0" maxOccurs="unbounded"/> 
            </s:sequence> 
         </s:complexType>
         <s:element name="items" type="tns:items" />
      </s:schema>
  </wsdl:types>
  <wsdl:message name="addItemsRequest">
     <wsdl:part name="items" type="tns:items" />
  </wsdl:message>
  <wsdl:message name="addItemsResponse">
     <wsdl:part name="parameters" type="tns:addItemsResponseElement"/>
  </wsdl:message>
  <wsdl:portType name="TestPortType">
    <wsdl:operation name="addItems">
      <wsdl:input message="tns:addItemsRequest" />
      <wsdl:output message="tns:addItemsResponse" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="LocalhostTestWebserviceBinding" type="tns:TestPortType">
 <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="addItems">
         <soap:operation soapAction="addItems" />
         <wsdl:input>
             <soap:body use="literal" namespace="urn:addItems" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </wsdl:input>
         <wsdl:output>
             <soap:body use="literal" namespace="urn:addItems" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
         </wsdl:output>
     </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="LocalhostTestWebservice">
    <wsdl:port name="LocalhostTestWebservicePort" binding="tns:LocalhostTestWebserviceBinding">
      <soap:address location="http://localhost/api/soap/test/" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

我没有测试此解决方案,但您可以检查:

在您的信息中部分:

<message name="getItemsResponse">
    <part name="items" type="ns:ArrayOfItems"/>
</message>
<xsd:schema targetNamespace="http://foo.bar/objectsoapserver/types"
            xmlns="http://foo.bar/objectsoapserver/types">
    <xsd:complexType name="ArrayOfItems">
        <xsd:complexContent>
            <xsd:restriction base="soapenc:Array">
                <xsd:attribute ref="soapenc:arrayType" soap:arrayType="ns:Items[]"/>
            </xsd:restriction>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="Items">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="id" type="xsd:int"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="Items" nillable="true" type="ns:Items"/>
</xsd:schema>

类型零件:

<message name="getItemsResponse">
    <part name="items" type="ns:ArrayOfItems"/>
</message>
<xsd:schema targetNamespace="http://foo.bar/objectsoapserver/types"
            xmlns="http://foo.bar/objectsoapserver/types">
    <xsd:complexType name="ArrayOfItems">
        <xsd:complexContent>
            <xsd:restriction base="soapenc:Array">
                <xsd:attribute ref="soapenc:arrayType" soap:arrayType="ns:Items[]"/>
            </xsd:restriction>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:complexType name="Items">
        <xsd:sequence>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="id" type="xsd:int"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="Items" nillable="true" type="ns:Items"/>
</xsd:schema>


顺便说一句,为什么不使用库自动生成WSDL?

您可以通过在您的SOAP服务器上启用
SOAP\u SINGLE\u ELEMENT\u Array
来解决此问题:

$server=newsoapserver('wsdl.xml'[
'features'=>SOAP\u单元素\u数组,
]);

你好,谢谢。我只是使用PHP的SoapServer类,所以有一个nog生成器类。但我确实用你的代码修复了它。VisualStudio仍然抱怨我不能使用数组编码类型为WS-I-mode。经过长时间的搜索,我发现我还必须将部分中的编码类型更改为“encoded”,而不是“literal”。