简体   繁体   English

在 PHP SOAP 中将 NULL 字符串传递给 WSDL

[英]Passing a NULL string to WSDL in PHP SOAP

Hi I am writing a PHP function to communicate with an external WSDL service and am currently experiencing an issue.您好,我正在编写一个 PHP 函数来与外部 WSDL 服务进行通信,目前遇到了一个问题。 There are dateTime elements that either need a valid date/time or need to have a NULL variable passed through to them.有一些 dateTime 元素需要有效的日期/时间或需要将 NULL 变量传递给它们。 For example:例如:

<s:element minOccurs="1" maxOccurs="1" name="dAppointment" type="s:dateTime"/>

A simplified version of the PHP function is like so: PHP 函数的简化版本如下所示:

$client = new SoapClient($this->SOAPURL, array("connection_timeout" => 20));

$params = new stdClass();
$params->dAppointment = NULL;
settype($params->dAppointment, "null");  // Trying to confirm

$client->AddJob($params)->AddJobResult;

The function works fine when a valid date is submitted but when trying to pass a NULL variable through the following error is returned:当提交有效日期时,该函数工作正常,但当尝试通过以下错误传递 NULL 变量时,返回:

The string '' is not a valid AllXsd value字符串 '' 不是有效的 AllXsd 值

Suggesting that the value is being converted to an empty string along the way.建议该值正在转换为空字符串。 Does the variable need to be set to NULL a different way like using SoapVar or could this be a problem at the WSDL end?变量是否需要像使用 SoapVar 那样以不同的方式设置为 NULL 或者这可能是 WSDL 端的问题?

Thanks for any help.谢谢你的帮助。

So, everybody who got this issue, solution:所以,每个遇到这个问题的人,解决方案:

  • Open your local.wsdl file打开您的local.wsdl文件
  • Find your field:找到你的领域:

<s:element minOccurs="1" maxOccurs="1" name="dAppointment" type="s:dateTime"/>

  • Change it to:将其更改为:

<s:element minOccurs="1" maxOccurs="1" name="dAppointment" type="s:dateTime" nillable="true" />

  • And now when you set variable as NULL it'll be NULL .现在,当您将变量设置为NULL它将是NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM