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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题