php - 在非 WSDL 模式下使用 PHP SOAP 客户端

标签 php web-services soap yii

我正在为客户开发 API。我收到了以下信息:

API Url: http://xyz-crm.example/WebAPI/Custom/project_name/XML/

Username: foobar
password: spameggs

我需要在非 WSDL 模式下配置 PHP SOAP 客户端。我写了以下内容,但它似乎不起作用:

$wsdl    = null;
$options = array(
    'uri'      => 'http://xyz-crm.example/WebAPI/Custom/project_name/XML/',
    'location' => 'http://xyz-crm.exmaple.com/WebAPI/Custom/project_name/XML/',
    'login'    => 'foobar',
    'password' => 'spameggs'
);
$client  = new SoapCLient($wsdl, $options);

我只想首先对 api 进行成功的 ping。看看一切是否正常。我在这里做错了什么?

更新 1

我做了以下更改:

$wsdl    = null;
$options = array(
    'uri'          => "http://xyz-crm.example/WebAPI/Custom/project_name/XML/",
    'location'     => "http://xyz-crm.example/",
    'Username'     => "foobar",
    'Password'     => "spameggs",
    'soap_version' => '1.2'
);
$client  = new SoapClient($wsdl, $options);
$client  = $client->getListings();

我得到错误:看起来我们没有 XML 文档

[Edit by me, hakre: This update was done as feedback to answer #1. It changes the location option using a shortened URL (reason not given by OP) and it adds the soap_version option (as suggested in answer #1, but not as constant but as string (containing an invalid value), so there should be no wonder this creates an error, a correct option value is given in answer #1 (the SOAP_1_1 constant) and by intention, the correct value would be the SOAP_1_2 constant for this example). Error message as commented by OP was "SOAP Fault: Wrong version."]

更新 2

我尝试了以下方法,但仍然失败:

$listing = $client->getListings(); 
$request = $client->__getLastRequest(); 

执行本身在第一行停止,而不会转到第二行。

[Edit by me, hakre: As review has shown wrong configuration options in Update 1 already which are not addressed in Update 2 it would be a miracle if it still wouldn't fail. The execution stops because an Exception is thrown and no error/exception handling is done]

最佳答案

URI 或文件结尾无关紧要,甚至可以是.jpg,没有默认值。

看看类似的问题:Does this SOAP Fault mean what I think it means?

如果您将错误消息以及请求的 XML 输出放入问题中,将会很有帮助。

尝试将 SoapClient 实例数组中的 SOAP 版本设置为常量之一(尝试不同的):

new SoapClient($url, array("soap_version" => SOAP_1_1,.......

SOAP_1_2 ...

要调试 XML,请尝试 Inspect XML created by PHP SoapClient call before/without sending the request 中的答案

您更新后的问题的错误消息看起来不像是来自 PHP,更像是来自网络服务的答案,这意味着您的请求确实有效。

关于php - 在非 WSDL 模式下使用 PHP SOAP 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19653275/

相关文章:

android - 在 Android 上使用哪种网络服务技术?

php - 使用 XPath 搜索和打印 XML

java - 当 URL 为 "+"时,JarURLConnection.connect 抛出 java.io.FileNotFoundException

java - 在 Spring 的 WebServiceTemplate 中设置超时

java - 如何通过 SOAP 进行 Windows Live 身份验证 (RST)

java - 在 Java 中处理 Content-Type = "application/x-www-form-urlencoded"的 SOAP 请求

php - echo MySql 列名和值

php - Mysql - Where IN 子句未正确选择数据

php - Mysql 查询最近的条目

asp.net - 如何在 Web 服务中返回 JSON?