在Symfony2中调用SOAP web服务


Calling SOAP web service in Symfony2

在我的Symfony2项目中,我需要对WebService进行SOAP调用,因此我使用composer安装了besimple/soap-client,并将其配置为:

parameters.yml:

soap选项(_O):wsdl:wsdl/test.wsdl

In-services.xml

<!-- Soap Client -->
<service id="project.test.soap.wrapper"
        class="Project'Test'Soap'SoapClientWrapper">
    <argument key="soap_options">%soap_options%</argument>
</service>

然后,我将此服务注入到我的一个Dto/TestTemplate.php 中

接下来,我在besimple/soap-client创建的Soap目录中创建了一个Repositorys目录,在这个存储库中我添加了TestAttrebiutes.php文件:

namespace Project'Test'Soap'Repositories;
class TestAttributes {
    public $agentID;
    public $sourceChannel;
    public $organisationName;
    public function __construct(
        $agentID,
        $sourceChannel,
        $organisationName,
    ){
        $this->$agentID = $agentID;
        $this->$sourceChannel = $sourceChannel;
        $this->$organisationName = $organisationName;
    }
} 

所以现在在我的TestTemplate.php中,我希望能做这样的事情:

$this->soap->__call(new FttpStatusAttributes(
    '100',
    'Web',
    'Ferrari'
), **ASKING FOR ATTRIBUTES);

但它要求我在添加属性后立即添加属性,我做错了什么?有可能按照我尝试的方式来做吗。。?

这段代码可能是问题所在:

$this->$agentID = $agentID;
$this->$sourceChannel = $sourceChannel;
$this->$organisationName = $organisationName;

当您访问$this->$agentID时,您正在访问值为$agentID$this的成员。例如,如果$agentIDjohn123,那么您的代码实际上意味着

$this->john123 = 'john123';

这显然不是你想要的。你的代码应该是:

$this->agentID = $agentID;
$this->sourceChannel = $sourceChannel;
$this->organisationName = $organisationName;

老实说,我不知道这是否能解决问题,因为你的问题有点模糊,但这肯定是你想解决的问题。