SoapClient不发送参数

时间:2014-05-19 09:09:03

标签: php soap wsdl

我正把头发拉出来。我尝试了很多不同的方法,但没有任何作用:

<?php

// Proxy is for Fiddler
$soap = new soapClient( 'http://testi.lemonsoft.eu:22000/CTP/lemonweb/userservices.svc?wsdl',     array(
    'proxy_host' => 'localhost',
    'proxy_port' => '8888'
)); 
try { 
    $test = new stdClass();
    $test->UserName = "foo";
    $test->Password = "bar";
    $test->CompanyDatabase = "baz";

    // This should work:
    print_r($soap->LogIn($test));

    /** The rest are alternative experiments, no avail: **/

    print_r($soap->LogIn(array($test)));

    print_r($soap->LogIn(array('parameters' => $test)));

    print_r($soap->login(array(
        'UserName' => 'foo',
        'Password' =>'bar',
        'CompanyDatabase' => 'baz'
    )));

    print_r($soap->__soapCall('LogIn', array('parameters' => $test)));

    print_r($soap->__soapCall('LogIn', array('parameters' => array(
        'UserName' => 'foo',
        'Password' =>'bar',
        'CompanyDatabase' => 'baz'
    ))));

    print_r($soap->LogIn(new SoapParam($test, "LogIn")));

    print_r($soap->LogIn(new SoapParam(array(
        'UserName' => 'foo',
        'Password' =>'bar',
        'CompanyDatabase' => 'baz'
    ), "LogIn")));

    print_r($soap->__soapCall('LogIn', array('parameters' => array(
        new SoapParam(array(
            'UserName' => 'foo',
            'Password' =>'bar',
            'CompanyDatabase' => 'baz'
        ), "LogIn")
    ))));

} catch (SoapFault $fault) { 
    print_r($fault);
}

?>

我用fiddler捕获了请求,响应总是如下:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
    <SOAP-ENV:Body>
        <ns1:LogIn/>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

好像永远不会发送LogIn参数。空ns1:LogIn标签真的意味着什么?中间是否有一些实例,我无法控制,出于某种原因剥离参数?根据我的理解,LogIn方法接受一个参数,根据文档,该参数应该是PHP stdClass。

3 个答案:

答案 0 :(得分:3)

试试这个:

class LogInInfo{
    public $UserName = '1';
    public $Password = '2';
    public $CompanyDatabase = '3';
}

ini_set('display_error', 1);
error_reporting(E_ALL);

$client = new SoapClient('http://testi.lemonsoft.eu:22000/CTP/LemonWeb/UserServices.svc?singleWsdl', array(
        'classmap'=>array('LogInInfo'=>'LogInInfo'),
        'debug'=>true,
        'trace'=>true
    ));

try {
    $info = new LogInInfo();
    $resp = $client->LogIn($info);


} catch(Exception $e) {
    var_dump($e);
}

print_r($client->__getLastRequest());

结果:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.datacontract.org/2004/07/Lemonsoft.LemonsoftServiceLibrary.User" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://tempuri.org/">
<SOAP-ENV:Body>
    <ns2:LogIn xsi:type="ns1:LogInInfo">
        <ns1:CompanyDatabase>3</ns1:CompanyDatabase>
        <ns1:Password>2</ns1:Password>
        <ns1:UserName>1</ns1:UserName>
    </ns2:LogIn>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

答案 1 :(得分:0)

你能展示WSDL文件的内容吗?

ns1:LogIn标记表示方法LogIn来自ns1名称空间(在上面定义)。

答案 2 :(得分:0)

我设法从PHP传递SOAP请求中的params的唯一方法是:

// __setSoapHeaders here

$listCriteriaXML = '<List xmlns="LINKHERE">
  <listCriteria>
    <ListCriterion>
      <Name>DateNeeded</Name>
      <SingleValue>' . date("Y-m-d", strtotime("+120 days")) . '</SingleValue>
    </ListCriterion>
    <ListCriterion>
      <Name>limitresults</Name>
      <SingleValue>false</SingleValue>
    </ListCriterion>
  </listCriteria>
</List>';

$listCriteria = new SoapVar($listCriteriaXML, XSD_ANYXML);

$response = $client->List($listCriteria);

echo $client->__getLastRequest();