php - SoapClient 不发送参数

标签 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>

好像从未发送过登录参数。空的 ns1:LogIn 标签真的是这个意思吗?由于某种原因剥离参数,中间是否有一些我无法控制的实例?根据我的理解,LogIn 方法采用一个参数,根据文档,该参数应该是一个 PHP stdClass。

最佳答案

试试这个:

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>

关于php - SoapClient 不发送参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23733850/

相关文章:

javascript - 了解 ajax 在做什么

php - 电子邮件正文 php 中的 array_chunk

php - WordPress-统计所有用户的帖子

asp.net - Soap 和 Rest Web 服务

java - 如何解析 SOAP 响应

java - Spring Boot SOAP Web 服务的 EndpointNotFound 异常

使用 HTTP POST 和 GET 绑定(bind)的 iPhone WSDL 服务

java - 如何从 axis1 stub 获取传输的响应 header

java - 如何配置 axis2-java2wsdl-maven-plugin 使用多个类生成一个 wsdl?

php - 如何停止 jQuery post 页面刷新