编程语言
首页 > 编程语言> > 是否有可能将元素名称映射到php类(SoapClient)

是否有可能将元素名称映射到php类(SoapClient)

作者:互联网

使用SoapClient,是否可以将元素名称(而不是类型)映射到php类?

在php手册中:

http://www.php.net/manual/en/soapclient.soapclient.php

这样定义了类映射:

The classmap option can be used to map some WSDL types to PHP classes. This option must be an array with WSDL types as keys and names of PHP classes as values.

如果没有类型,可以映射一个元素吗?

例如.

<xsd:element name="M1Response">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="N1Response" type="bons0:R1Out"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

即.我想将元素M1Response映射到php类

我可以将N1Response映射到php类,但响应如下:

stdClass Object
(
    [N1Response] => MyPHPClassResponse Object
        (
            ...
        )
)

这几乎违反了类映射功能的目的.

任何帮助,将不胜感激.

谢谢

解决方法:

所以我误解了类型的定义

在以下示例中,type不是R1Out:

<xsd:element name="N1Response" type="bons0:R1Out"/>

实际上是这种类型:

$options['classmap'] = array('M1Response' => 'MyPHPClassResponse');
$client = new SoapClient('test.wsdl', $options);
$client->__getTypes();

检查__getTypes()的输出表明,确实存在与M1Response元素关联的类型:

struct M1Response {
    R1Out N1Response;
}

因此答案是(如上所述):

$options['classmap'] = array('M1Response' => 'MyPHPClassResponse');

标签:soap-client,wsdl,xml,php
来源: https://codeday.me/bug/20191030/1971421.html