SoapClient not returning expected response from a call of its function

41 views Asked by At

I'm new to PHP and SOAP. I'm trying to connect to a soap service and call one of its functions. I'll try putting relevant WSDL parts below:

<wsdl:binding name="ServiceSoap" type="tns:ServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Function">
<soap:operation soapAction="http://test.com/Function" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
<soap:header message="tns:FunctionSC" part="SC" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
<soap:header message="tns:FunctionSC" part="SC" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:message name="FunctionSC">
<wsdl:part name="SC" element="tns:SC"/>
</wsdl:message>
<s:element name="SC" type="tns:SC"/>
<s:complexType name="SC">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="user" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="pass" type="s:string"/>
</s:sequence>
<s:anyAttribute/>
</s:complexType>

This is my PHP code:

<?php
class sc
{
    public $user;
    public $pass;
}

$sC = new sc();
$sC->user = "";
$sC->pass = "";

$host = "https://...";

$opts = array(
    'ssl' => array(
        'verify_peer' => false
    )
);
$streamContext = stream_context_create($opts);
$soapClient = @new SoapClient(
    $host,
    array(
        'location' => $host,
        'connection_timeout' => 4,
        'cache_wsdl' => WSDL_CACHE_MEMORY,
        'soap_version' => SOAP_1_1,
        'ssl_method' => SOAP_SSL_METHOD_TLS,
        'trace' => 1,
        'stream_context' => $streamContext
    )
);
$auth = array(
    'user' => $sC->user,
    'pass' => $sC->pass
);
$header = new SoapHeader('FunctionSC', 'SC', $auth);
$soapClient->__setSoapHeaders($header);

$response = $soapClient->Function(null);
print_r($response);

I'm successfully connecting to a service as var_dump($soapClient->__getFunctions()); returns functions (including the one I need). The result of print_r is: stdClass Object ( [FunctionResult] => stdClass Object ( ) [errorMsg] => Object reference not set to an instance of an object. ) And I know that FunctionResult should return something.

Am I doing something wrong or is it something on the service's part?

0

There are 0 answers