John
John

Reputation: 1665

Calling SOAP web service in Symfony2

In my Symfony2 project I need to make a SOAP call to a WebService, So I have installed besimple/soap-client using composer and configured it like this:

parameters.yml:

soap_options: 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>

I then injected this service into one of my Dto/TestTemplate.php

Next i created a Repositories directory in my Soap directory created by besimple/soap-client, in this repository I added TestAttrebiutes.php file:

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;
    }
} 

SO now in my TestTemplate.php i would expect to do something like this:

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

but it is asking me to add attributes right after i add them, what am I doing wrong is it possible to do the way I am trying to do it..?

Upvotes: 1

Views: 1181

Answers (1)

lxg
lxg

Reputation: 13127

This code might be the problem:

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

When you access $this->$agentID, you’re accessing a member of $this which has the value of $agentID. So e.g. if $agentID was, say, john123, your code would actually mean

$this->john123 = 'john123';

This is clearly not what you want. Your code should read:

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

To be honest, I don’t know if that solves the problem, as your question is a bit vague, but this is definitely something you’ll want to fix.

Upvotes: 1

Related Questions