如何阻止 PHP SoapClient 将请求中的 s1:char 参数转换为 0 或 1

发布于 2024-12-06 10:44:31 字数 949 浏览 2 评论 0原文

PHP 的 Soap 客户端在构建请求时似乎错误地处理了 s1:char 类型的参数。 Soap API 需要“Y”或“N”,但在请求 XML 中我得到“0”。 (传递 Bool true 会导致“1”,但不接受 API 来代替“Y”)。

我正在使用 PHP 版本 5.3.8 和本机 Soap 客户端

这是我的 PHP

$this->soapClient = new SoapClient( $client->wsdl,
  array(
    'soap_version' => SOAP_1_2,
    'trace' => true
  )
);

$result = $this->soapClient->SomeSoapMethod(array(
  'sSessionKey'        => $sessionKey,
  // other string and int args that work fine here
  'cReturnNonSeats'    => 'Y' // API wants 'Y' or 'N'
));

请求 XML 中的相关 XML 节点:

<ns1:cReturnNonSeats>0</ns1:cReturnNonSeats>

以及来自 WSDL:

    <s:complexType>
      <s:sequence>
        <s:element minOccurs="1" maxOccurs="1" name="cReturnNonSeats" type="s1:char" />
      </s:sequence>
    </s:complexType>

无需手动构建 XML,有没有一种方法可以控制这些参数是类型转换的吗?

PHP's Soap client appears to be handling arguments with type s1:char incorrectly when building the request. The Soap API requires either 'Y' or 'N' but in the request XML I get '0'. (Passing Bool true results in '1' but that isn't accepted as API in place of 'Y').

I'm using PHP Version 5.3.8 with the native Soap Client

Here's my PHP

$this->soapClient = new SoapClient( $client->wsdl,
  array(
    'soap_version' => SOAP_1_2,
    'trace' => true
  )
);

$result = $this->soapClient->SomeSoapMethod(array(
  'sSessionKey'        => $sessionKey,
  // other string and int args that work fine here
  'cReturnNonSeats'    => 'Y' // API wants 'Y' or 'N'
));

The relevant XML node in the request XML:

<ns1:cReturnNonSeats>0</ns1:cReturnNonSeats>

And from the WSDL:

    <s:complexType>
      <s:sequence>
        <s:element minOccurs="1" maxOccurs="1" name="cReturnNonSeats" type="s1:char" />
      </s:sequence>
    </s:complexType>

Without getting into building XML manually, is there a way I can have some control over how these arguments are typecast?

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

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

发布评论

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

评论(1

洛阳烟雨空心柳 2024-12-13 10:44:31

这就是我解决这个问题的方法,尽管我现在想知道为什么 SoapClient 将该字符串转换为 int。

我使用的不是参数数组中的“Y”:

new SoapVar('Y', XSD_ANYTYPE)

This is how I got around it though I'd like to now why SoapClient is converting that string to int.

Instead of 'Y' in my array of parameters, I used:

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