【问题标题】:How can I pass in an array as a value into a PHP soapclient request?如何将数组作为值传递给 PHP soapclient 请求?
【发布时间】:2010-02-25 21:47:52
【问题描述】:

如何将数组作为值传递给 PHP soapclient 请求?

我已经实例化并连接了一个soapclient。然后我尝试调用一个需要 3 个参数(字符串、字符串、哈希图)的 web 服务方法。

这是我期望在下面工作的。但是查看xml输出的时候,params节点是空的。

soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 'params' => array('email' => 'test@test.com', 'password' => 'password', 'blah' => 'blah')));

soap body xml 最终是这样的(注意空的 params 元素):

<SOAP-ENV:Body><ns1:doSomething>
<id>blah</id>
<page>blah</page>
<params/>
</ns1:register></SOAP-ENV:Body>

【问题讨论】:

    标签: php xml arrays soap soap-client


    【解决方案1】:

    对于 JAX-WS Web 服务,可能是 hashmap 输入参数有问题。生成的 xsd 模式似乎对于哈希图不正确。将映射放在包装器对象中会导致 JAX-WS 输出正确的 xsd。

    public class MapWrapper {
        public HashMap<String, String> map;
    }
    
    
    // in your web service class
    @WebMethod(operationName = "doSomething")
    public SomeResponseObject doSomething(
            @WebParam(name = "id") String id,
            @WebParam(name = "page") String page,
            @WebParam(name = "params") MapWrapper params {
        // body of method
    }
    

    那么php代码就成功了。我发现我不需要 SoapVar 或 SoapParam,而且如果没有 MapWrapper,这两种方法都无法工作。

    $entry1['key'] = 'somekey';
    $entry1['value'] = 1;
    $params['map'] = array($entry1);
    soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 
        'params' => $params));
    

    这是使用包装器生成的正确 xsd

    <xs:complexType name="mapWrapper">
      <xs:sequence>
        <xs:element name="map">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="key" minOccurs="0" type="xs:string"/>
                    <xs:element name="value" minOccurs="0" type="xs:string"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
    

    这是由 JAX-WS 仅使用哈希图生成的不正确模式

    <xs:complexType name="hashMap">
      <xs:complexContent>
        <xs:extension base="tns:abstractMap">
          <xs:sequence/>
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="abstractMap" abstract="true">
      <xs:sequence/>
    </xs:complexType>
    

    最后一点。包装 HashMap 与此解决方案一起使用,但 HashMap 没有。对象被映射到 xsd:anyType,它作为一个 xsd 模式对象进入 java web 服务,而不仅仅是对象。

    【讨论】:

      【解决方案2】:

      根据 web 服务定义,hashmap 参数可能需要具有无法直接从数组创建的特定结构/编码。您可能需要检查 WSDL,并查看 SoapVarSoapParam 类以获取有关 Soap 参数构造的更多选项。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-30
        • 1970-01-01
        相关资源
        最近更新 更多