【问题标题】:How to explicitly set parameter type for NuSOAP in PHP如何在 PHP 中为 NuSOAP 显式设置参数类型
【发布时间】:2013-01-19 07:00:20
【问题描述】:

使用 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);
        }
    }
}

【问题讨论】:

    标签: php soap wsdl nusoap


    【解决方案1】:

    我能够使用“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);
    

    【讨论】:

    • soapval 是什么?你是说SoapVar 吗?
    猜你喜欢
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    • 2019-05-20
    相关资源
    最近更新 更多