如何将数组作为值传递到 PHP Soapclient 请求中?

发布于 2024-08-23 04:24:40 字数 706 浏览 4 评论 0原文

如何将数组作为值传递到 PHP Soapclient 请求中?

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

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

soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 'params' => array('email' => '[email protected]', 'password' => 'password', 'blah' => 'blah')));

肥皂体 xml 最终如下所示(注意空的 params 元素):

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

How can I pass in an array as a value into a PHP soapclient request?

I have a soapclient instantiated and connected already. I then try to make a call to a webservice method that expects 3 parameters (string, string, hashmap).

Here is what I expected to work below. But when viewing the xml output, the params node is empty.

soapclient->doSomething(array('id' => 'blah', 'page' => 'blah', 'params' => array('email' => '[email protected]', 'password' => 'password', 'blah' => 'blah')));

The soap body xml ends up like this (note the empty params element):

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凌乱心跳 2024-08-30 04:24:40

对于 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 仅使用 hashmap 生成的不正确模式

<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 webservice。

For JAX-WS webservices it may be a problem with the hashmap input parameter. The xsd schema generated seems to be incorrect for hashmaps. Placing the map in a wrapper object causes JAX-WS to output the correct 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
}

Then the php code will succeed. I found I didn't need SoapVar or SoapParam and could not get either of those methods to work without the MapWrapper.

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

Here is the correct xsd generated with the wrapper

<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>

Here is the incorrect schema generated by JAX-WS with just the hashmap

<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>

One last note. Wrapping HashMap<String, String> worked with this solution, but HashMap<String, Object> did not. The Object gets mapped to xsd:anyType which comes into the java webservice as a xsd schema object rather than just Object.

客…行舟 2024-08-30 04:24:40

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

Depending on the webservice definition, the hashmap parameter might need to have a specific structure/encoding that can not be directly created from an array. You might want to check the WSDL on that, and take a look into the SoapVar and the SoapParam classes for more options on Soap parameter construction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文