Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple function parameters as objects #42

Open
Krysaior opened this issue Oct 5, 2021 · 1 comment · May be fixed by #45
Open

Multiple function parameters as objects #42

Krysaior opened this issue Oct 5, 2021 · 1 comment · May be fixed by #45

Comments

@Krysaior
Copy link

Krysaior commented Oct 5, 2021

I have issue with multiple parameters in soap function call. I can assign parameters as objects to function and using native SoapClient I can create working request like this:

$soapClient = New SoapClient($this->baseURL, $options);
$response = $soapClient->my_method($apiKeys, $files);

Now, with Soap::to this is not possible as __call() accepts only first parameter resulting xml missing files part. This is how I thought it should work:

$response = Soap::to($this->baseURL)->my_method($apiKeys, $files);

Also notice, that $apiKeys and $files are objects:

class ApiKeys
{
    protected $user_api_key = null;
    protected $vendor_api_key = null;
    protected $company_uuid = null;

    public function __construct($user_api_key = null, $vendor_api_key = null, $company_uuid = null)
    {
        $this->user_api_key = $user_api_key;
        $this->vendor_api_key = $vendor_api_key;
        $this->company_uuid = $company_uuid;
    }
}
class Files
{
    protected $files = null;
    protected $filenames = null;

    public function __construct($files = null, $filenames = null)
    {
        $this->files = $files;
        $this->filenames = $filenames;
    }
}

And here is the wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="MyTestWsdl" targetNamespace="https://my_test.test/" xmlns:typens="https://my_test.test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="https://my_test.test/">
      <xsd:complexType name="ApiKeys">
        <xsd:all>
          <xsd:element name="user_api_key" type="xsd:string"/>
          <xsd:element name="vendor_api_key" type="xsd:string"/>
          <xsd:element name="company_uuid" type="xsd:string"/>
        </xsd:all>
      </xsd:complexType>
      <xsd:complexType name="Files">
        <xsd:all>
          <xsd:element name="filenames" type="typens:StringArray"/>
          <xsd:element name="files" type="typens:ActionWebService..Base64Array"/>
        </xsd:all>
      </xsd:complexType>
    </xsd:schema>
  </types>
  <message name="api-my_method">
    <part name="api_keys" type="typens:ApiKeys"/>
    <part name="files_in" type="typens:Files"/>
  </message>
  <message name="api-my_methodResponse">
    <part name="return" type="typens:InvoiceStatus"/>
  </message>
  <portType name="ApiPort">
    <operation name="my_method">
      <input message="typens:api-my_method"/>
      <output message="typens:api-my_methodResponse"/>
    </operation>
  </portType>
  <binding name="ApiBinding" type="typens:ApiPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="my_method">
      <soap:operation soapAction="/api/my_method"/>
      <input>
        <soap:body use="encoded" namespace="https://my_test.test/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded" namespace="https://my_test.test/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>
  <service name="Service">
    <port name="ApiPort" binding="typens:ApiBinding">
      <soap:address location="https://my_test.test/"/>
    </port>
  </service>
</definitions>

Here is expected soap request:

<?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://my_test.test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:my_method>
            <api_keys xsi:type="ns1:ApiKeys">
                <user_api_key xsi:type="xsd:string">00000000-1111-2222-3333-444444444444</user_api_key>
                <vendor_api_key xsi:type="xsd:string">00000000-1111-2222-3333-444444444444</vendor_api_key>
                <company_uuid xsi:type="xsd:string">00000000-1111-2222-3333-444444444444</company_uuid>
            </api_keys>
            <files_in xsi:type="ns1:Files">
                <filenames SOAP-ENC:arrayType="xsd:string[1]" xsi:type="ns1:StringArray">
                    <item xsi:type="xsd:string">file.xml</item>
                </filenames>
                <files SOAP-ENC:arrayType="xsd:string[1]" xsi:type="ns1:ActionWebService..Base64Array">
                    <item xsi:type="xsd:string">PD94bWw/PjxGaW52b2ljZT48L0ZpbnZvaWNlPg==</item>
                </files>
            </files_in>
        </ns1:my_method>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Is it possible to add support for multiple parameters (not just array) in __call method to make it work more like php's native SoapClient function call?

@lukeraymonddowning
Copy link
Contributor

Hey @Krysaior!

Sounds like you know what you're doing here. Any chance you could create a PR with tests? I'd be happy to accept. If not, we're a little rushed off our feet at the moment, so my answer is "yes, but I can't give you a timeframe".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants