简体   繁体   中英

PHP SOAP client with authentication required in function call

I'm completely new to using SOAP, and am looking to create some client software connecting to an existing service that provides no resources/demo's for PHP. I'd like to determine if I'm doing something wrong with my code, or if it's perhaps a systems issue (I've created an Apache2.4/PHP7.2.7 on Windows Server 2008 R2 environment).

I've already spent hours going testing things and going through the numerous other SOAP/PHP topics on here, and the point of distinction I've where I'm making my own thread is that the authentication is required in the SoapClient call but rather the $client->__soapCall(function, params)call.

First this is what I have in PHP.

$customerArray = array( $cust1 , $cust2, $cust3 );
$credentials = array(
 'login' => $login,
 'password' => $password,
);  

try{
    $client = new SoapClient($soaplink);//, $credentials);
} catch (Exception $e) {
    echo "<h2>Exception Error in SoapClient</h2>";
    echo $e->getMessage();
}   
var_dump($client->__getFunctions());

try{
    $response = $client->__soapCall("getCustomers", array($customerArray, $credentials));
}catch (Exception $e) {
    echo "<h2>Exception Error in soapCall</h2>";
    echo $e->getMessage();
}   
var_dump($response());

The first try block completes, with or without the credentials array. The second try block when trying to call the function returns the exception "looks like we got no XML document".

The SOAP service provided demo XML files, the one for this function looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <ns1:getCustomers 
            soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
            xmlns:ns1="http://ws.praxedo.com/2008_07_01/customermodel/service"
        >
            <in0 
                soapenc:arrayType="soapenc:string[3]" 
                xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
            >
                <in0 xsi:type="soapenc:string">CUSTOMER001</in0>
                <in0 xsi:type="soapenc:string">CUSTOMER002</in0>
                <in0 xsi:type="soapenc:string">CUSTOMER003</in0>
            </in0>
            <in1 
                xsi:type="soapenc:string" 
                xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
            >
                login|password
            </in1>
        </ns1:getCustomers>
    </soapenv:Body>
</soapenv:Envelope>

WSDL files were also provided, it could be I need to load from that but following a demo to do so provided no results. I could include some of the WSDL here but I believe the XML provides all the relevant details?

So can anyone see if there's something I'm doing wrong here in my PHP, or should what I'm doing work and I need to look into the client Apache/SOAP server side?

I strongly advise you to use a WSDL to PHP generator as it'll allow you to construct the request without any wondering (depending on your PHP knowledge level at the least).

Try the PackageGenerator project. You have to install it then generate the PHP SDK. The generated SDK uses composer and contains all the classes and methods required to send any request. Take a look to the auto-generated tutorial.php file which is a good starting point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM