非常奇怪的 SoapClient 问题

发布于 2024-11-28 05:51:48 字数 755 浏览 2 评论 0原文

 try
  {
    $client = new \SoapClient($wsdlUrl, array(
      'cache_wsdl' => 0, 'exceptions' => true, 'trace' => true));

    $client->getPage($parameter);
  }
  catch(\Exception $e)
  {
    die("exception");
  }

好的,这就是执行 SOAP 请求的内容。 $wsdlUrl 保存 WSDL URL,$parameter 保存 XML 文档。

一切都像魅力一样!

现在我只需在 $parameter 中的 XML 文档中添加几个节点,就会收到致命错误。

这不一定很奇怪,但奇怪的是以下三个观察结果的组合:

1) 异常设置为 true .... 但没有抛出异常 / 这是 b/c 我忘记放置反斜杠catch 语句中的 Exception 之前

2) 相反,会记录错误:

PHP Fatal error:  SoapClient::SoapClient(): 
'uri' option is required in nonWSDL mode in /var/w[...]

3) 但提供了 WSDL url,并且当然是有效的,因为在跳过添加新节点后,所有内容都可以正常工作。它们不影响 wsdl 参数。

 try
  {
    $client = new \SoapClient($wsdlUrl, array(
      'cache_wsdl' => 0, 'exceptions' => true, 'trace' => true));

    $client->getPage($parameter);
  }
  catch(\Exception $e)
  {
    die("exception");
  }

Okay this is what executes the SOAP request. $wsdlUrl holds the WSDLs URL and $parameter keeps an XML document.

And everything works like a charm!

Now I just add few more nodes to the XML document in $parameter and I get a fatal error.

This is not so weird necessarily, but what is weired is the combination of following three observations:

1) exceptions is set to true .... but no Exception is thrown / this was b/c I forgot to place a backslash before Exception in the catch statement.

2) instead an error is logged:

PHP Fatal error:  SoapClient::SoapClient(): 
'uri' option is required in nonWSDL mode in /var/w[...]

3) but the WSDL url is provided and of course valid, as all works again just fine after skipping the adding of the new nodes. they don't affect the wsdl parameter.

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

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

发布评论

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

评论(1

心作怪 2024-12-05 05:51:48

好的,我找到了问题的根源。这个问题确实没有令人满意的答案,但需要学习的东西却很少! :)

重要的是请求已经被 SOAP 服务器发送并处理。
但服务器响应错误。

因此,显然,即使触发关于没有 wsdl 且没有连接参数的致命错误并不意味着没有发送请求 - 在我看来,如果没有 wsdl,这是非常反逻辑的提供了并且没有连接参数,那么如何执行请求呢?

编辑

代码中还有另一个错误。我忘了在 Exception 之前加一个反斜杠!没有它就不会引用 Exception 类。

然后抛出并捕获异常。

Okay, I tracked down the source of the problem. There is no satisfying answer really to that question but few things to learn! :)

The important thing is that the request has been sent and processed by the SOAP server.
But the server responds with an error.

So, obviously, even though a fatal error regarding no wsdl and no connection parameter is triggered doesn't mean no request has been sent - which is very counter logical in my opinion b/c if no wsdl is provided and no connection params as well, then how could the request be executed?

EDIT

There is another bug in the code. I forgot to place a backslash before Exception! Without it's not referring to the Exception class.

Then an exception is thrown and caught.

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