php - 如何在 PHP 中显式设置 NuSOAP 的参数类型

标签 php soap wsdl nusoap

当使用 NuSOAP 进行 SOAP 调用时,我收到 SOAP 错误:

没有针对 {http://www.w3.org/2001/XMLSchema}anyType 的解串器

请求如下所示:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:impl="http://rtw.dncrtelem" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
  <SOAP-ENV:Body>
    <impl:WashNumbers xmlns:impl="http://rtw.dncrtelem">
      <TelemarketerId xsi:type="xsd:string">****</TelemarketerId>
      <WashOnlyUserId xsi:type="xsd:string">****</WashOnlyUserId>
      <TelemarketerPassword xsi:type="xsd:string">****</TelemarketerPassword>
      <ClientReferenceId xsi:type="xsd:string">****</ClientReferenceId>
      <NumbersToWash xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[2]">
        <item xsi:type="xsd:anyType">1234567890</item>
        <item xsi:type="xsd:anyType">0987654321</item>
      </NumbersToWash>
    </impl:WashNumbers>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如果我将请求粘贴到soapUI中并将“item”的类型从“xsd:anyType”更改为“xsd:string”,那么它就可以正常工作。 例如

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 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:impl="http://rtw.dncrtelem" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
  <SOAP-ENV:Body>
    <impl:WashNumbers xmlns:impl="http://rtw.dncrtelem">
      <TelemarketerId xsi:type="xsd:string">****</TelemarketerId>
      <WashOnlyUserId xsi:type="xsd:string">****</WashOnlyUserId>
      <TelemarketerPassword xsi:type="xsd:string">****</TelemarketerPassword>
      <ClientReferenceId xsi:type="xsd:string">****</ClientReferenceId>
      <NumbersToWash xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:anyType[2]">
        <item xsi:type="xsd:string">1234567890</item>
        <item xsi:type="xsd:string">0987654321</item>
      </NumbersToWash>
    </impl:WashNumbers>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

在构造 SOAP 调用时如何显式设置其类型?已经搜索过,但似乎找不到解决方案。

这是我的 PHP 代码:

include_once('lib/nusoap.php');

$client = new nusoap_client('https://www.donotcall.gov.au/dncrtelem/rtw/washing.cfc?wsdl', 'wsdl');

$err = $client->getError();
if($err){
    // Error handling here
} else {
    $client->setUseCurl(true);
    $client->soap_defencoding = 'UTF-8';
    $params = array('TelemarketerId'=>'****', 'WashOnlyUserId'=>'****', 'TelemarketerPassword'=>'****', 'ClientReferenceId'=>'****', 'NumbersToWash'=>array('1234567890','0987654321'));
    $result = $client->call('WashNumbers', $params);

    if ($client->fault) {
        // Fault handling here
    } else {
        $err = $client->getError();     
        if ($err) {
            // Error handling here
        } else {
            print_r($result);
        }
    }
}

最佳答案

我能够使用“soapval”解决此问题,代码更改如下:

$numbers = array('1234567890','0987654321');
$sv1 = array();
foreach ($numbers as $index => $number) {
    $sv1[] = new soapval('Number', 'xsd:string', $number);
}
$params = array('TelemarketerId'=>'****', 'WashOnlyUserId'=>'****', 'TelemarketerPassword'=>'****', 'ClientReferenceId'=>'****', 'NumbersToWash'=>$sv1);

关于php - 如何在 PHP 中显式设置 NuSOAP 的参数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14411959/

相关文章:

php - 代码点火器安全

java - C# WCF 客户端绑定(bind) 互操作 Blackboard Java WS-Security over HTTPS 传输

c# - gSOAP 客户端的 WCF 服务

ios - 在 Objective C(iOS 应用程序)中请求 WCF Web 服务时收到 SOAP 错误

java - 如何在现有应用程序中为 Quickbooks 连接器创建 Web 服务?

java - 如何在 Java 代码中使用 WSDL 文件中的用户定义数据类型?

php - 使用php从mysql动态追加数据到html表中

php - 如何重写 URL,使用户看起来好像在他们不在的地方?

php - 终端和 PHP 中的 PATH 不同

php - 在 Magento 中通过 SOAP 将产品添加到购物车时设置自定义选项