Map
Connect to an PHP/SOAP or ASP.NET/SOAP web service with PHP and how to create a PHP SOAP web service (server)

Related


Info Summary[-][--][++]

Learn how to connect to an an PHP/SOAP or ASP.NET/SOAP web service with PHP and how to create a PHP SOAP web service (server)

Code PHP SOAP Client[-][--][++]

Code PHP Client Connect to ASP.NET ASMX[-][--][++]

Here are two different methods for connecting to the ASP.NET .asmx file

Method 1

/*
Soap Client
Connect to an ASP.NET SOAP webservice
References: http://metrix.fcny.org/wiki/display/tips/How+to+Create+a+PHP+Client+for+a+.NET+and+SOAP-based+Web+Service+API
mReschke 2011-11-16

In this example, we have a webservice function called GetSpif that takes one parameter _spifID
*/

try {
    $client = new SoapClient("http://example.com/webservices/spifs.asmx?wsdl");
    
    //Parameters must be an associative array
    $params = array();
    $params["_spifID"] = 2;
    
    $result = $client->GetSpif($params)->GetSpifResult;

    var_dump($result);
    echo "
"; echo $result->ownerID."
"; echo $result->spifTypeID; } catch (Exception $e) { echo "Error!
"; echo $e -> getMessage (); } ?>

Method 2

/*
Soap Client
Connect to an ASP.NET SOAP webservice
References: http://php.net/manual/en/soapclient.soapcall.php
mReschke 2011-11-16

In this example, we have a webservice function called GetSpif that takes one parameter _spifID
*/

class Test {
    public $_spifID;
}

$parameters = new Test;
$parameters->_spifID = 2;

try {
    $client = new SoapClient ("http://example.com/webservices/spifs.asmx?wsdl", array('classmap' => array('GetSpif' => 'Test')));
    $result = $client->GetSpif($parameters);
    var_dump($result);
    echo "Success";
}
catch (Exception $e) {
    echo "Error!
"; echo $e -> getMessage (); }

Code PHP Client Connect to PHP SOAP Service[-][--][++]

This would be the example PHP SOAP server

/*
 PHP SOAP Server From: http://www.ibm.com/developerworks/opensource/tutorials/os-php-webservice/section3.html
*/
function echoo($echo){
    return "ECHO: ".$echo;
}

$server = new SoapServer(null, array('uri' => "urn://tyler/res"));
$server->addFunction('echoo');
$server->handle();

And here is the PHP SOAP client connecting to the PHP SOAP server

try {
    /* This connects to a PHP SOAP server, not an ASP.NET asmx SOAP server */
    /* PHP Client connecting to PHP SOAP webservice from http://www.ibm.com/developerworks/opensource/tutorials/os-php-webservice/section3.html */
    $client = new SoapClient(NULL, array(
                             'location' => "http://example.com/soap/server1.php",
                             'uri'      => "urn://tyler/req"));
    $result = $client->__soapCall("echoo", array('Waz Up SOAP!!'));
    
    var_dump($result);
    echo "
"; print $result; } catch (Exception $e) { echo "Error!
"; echo $e -> getMessage (); } ?>

Code PHP SOAP WebService (Server)[-][--][++]

/*
 PHP SOAP Server From: http://www.ibm.com/developerworks/opensource/tutorials/os-php-webservice/section3.html
*/
function echoo($echo){
    return "ECHO: ".$echo;
}

$server = new SoapServer(null, array('uri' => "urn://tyler/res"));
$server->addFunction('echoo');
$server->handle();

Resource Resources[-][--][++]