doulangpeng3933 2013-10-29 08:36
浏览 123

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

I am working on an api for a client. I have received the following information:

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

Username: foobar
password: spameggs

I need to configure the PHP SOAP client for the same in non-WSDL mode. I have written the following but it does not seem to work:

$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);

I just want to make a successful ping to the api at first. See if things are working fine. What am I doing wrong here?

Update 1

I made the following changes:

$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();

I get the error: looks like we got no XML document

[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."]

Update 2

I tried the following but it still fails:

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

The execution stops at the first line itself without ever going to the second one.

[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]

  • 写回答

1条回答 默认 最新

  • dongmu6578 2013-10-29 09:08
    关注

    Die URI or file ending does not matter, it could even be .jpg, there is no default.

    Have a look at similiar questions: Does this SOAP Fault mean what I think it means?

    It would be helpful if you put the error message into the question, aswell as the XML output of your request.

    try setting the SOAP Version in the array of your SoapClient instance to one of the constants (try different ones):

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

    or SOAP_1_2 ...

    To debug the XML try the answer from Inspect XML created by PHP SoapClient call before/without sending the request

    The error message of your updated question does not look like it coming from PHP, looks more like an answer from the webservice, means your request is actually working.

    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛