Using SOAP

Below are sample codes using PHP with NuSoap Library and Perl with SOAP:Lite. But before using PHP’s NuSOAP or Perl’s SOAP:Lite you need to download them, extract them and include “lib/nusoap.php” in your PHP code or install SOAP:Lite on your Perl library.

PHP's NuSOAP 1

<?php
require_once('lib/nusoap.php');

//Define RPX WSDL
$wsdl="http://api.rpxholding.com/wsdl/rpxwsdl.php?wsdl";
$client =new nusoap_client($wsdl,true);
$username = "UrRPXapi";
$password  = "UrP4ssW0rd";

$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}

// Calling RPX API method with parameters.
// Use your user & password provided after registering at http://api.rpxholding.com

$result = $client->call('getOrigin', array('user' => $username, 'password' => $password));

if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        print_r($result);
    }
}
?>

Try it here

PHP's NuSOAP 2

<?php
require_once('lib/nusoap.php');

//Define RPX WSDL
$wsdl="http://api.rpxholding.com/wsdl/rpxwsdl.php?wsdl";
$client =new nusoap_client($wsdl,true);
$username = "UrRPXapi";
$password  = "UrP4ssW0rd";
$origin = "JAK";
$dest = "BDO";
$weight = 2;
$disc = 0;
$format= "JSON";

$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}

// Calling RPX API method with parameters.
// Use your user & password provided after registering at http://api.rpxholding.com

$result = $client->call('getRates', array('user' => $username, 'password' => $password, 'origin' => $origin, 'destination' => $dest, 'weight' => $weight, 'disc' => $disc, 'format' => $format));

if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        print_r($result);
    }
}
?>

Try it here

PHP's SoapClient

<?php

$wsdl="http://api.rpxholding.com/wsdl/rpxwsdl.php?wsdl";
$client = new SoapClient($wsdl);
$username = "UrRPXapi";
$password  = "UrP4ssW0rd";

	echo "<pre>";
	try {
		$result = $client->getprovince($username,$password);
		echo "<br/>";
		var_dump($result);
	}
	catch ( Exception $e ) {
		echo $e->getMessage();
	}
?>

Perl's SOAP:Lite

#!"C:\xampp\perl\bin\perl.exe"
 
print "Content-type:text/html\r\n\r\n";
my %service_url = 'http://api.rpxholding.com/wsdl/rpxwsdl.php?wsdl';
 
use SOAP::Lite;
my $soap = SOAP::Lite->new( proxy => %service_url);
$soap->default_ns('urn:rpxwsdl');

##############################################################################################
# ALL INPUT PARAMETERS SHOULD BE ADDED (EVEN IF PARAMETER IS OPTIONAL OR VALUE IS NULL/ZERO) #
##############################################################################################
my $som = $soap->call('getRates',
   SOAP::Data->name('user')->value('UrRPXapi'),
   SOAP::Data->name('password')->value('UrP4ssW0rd'),
   SOAP::Data->name('origin')->value('JAK'),
   SOAP::Data->name('destination')->value('BDO'),
   SOAP::Data->name('service_type')->value(''),
   SOAP::Data->name('weight')->value('1'),
   SOAP::Data->name('disc')->value('0')
);
die $som->faultstring if ($som->fault);
print $som->result, "\n";

Android's (Java) ksoap2-android

/** Initiate Variables. */
private String METHOD_NAME = "getRates";  //find another method on List of Methods Page
private String NAMESPACE = "urn:rpxwsdl";
private String SOAP_ACTION = NAMESPACE + "#" + METHOD_NAME;
private String URL = "http://api.rpxholding.com/wsdl/rpxwsdl.php";

/** For Example, create this Function */
public String getRPXRates() {
	SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

	/**  #########################################################################################
	# ALL INPUT PARAMETERS SHOULD BE ADDED (EVEN IF PARAMETER IS OPTIONAL OR VALUE IS NULL/ZERO) #
	############################################################################################## */
	Request.addProperty("user","UrRPXapi");
	Request.addProperty("password","UrP4ssW0rd");
	Request.addProperty("origin","JAK");
	Request.addProperty("destination","BDO");
	Request.addProperty("service_type","");
	Request.addProperty("weight","1");
	Request.addProperty("disc","0");
		
	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	envelope.encodingStyle = SoapEnvelope.XSD;
	envelope.dotNet = false;
	envelope.setOutputSoapObject(Request);

	HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
	try
	{
		androidHttpTransport.debug = false;
		androidHttpTransport.call(SOAP_ACTION, envelope);
		Object response = (Object) envelope.getResponse();
		String result = response.toString();
	
		return result;
	}
	catch(Exception e)
	{
		return "Error";
	}
}

@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	String XMLRates = getRPXRates();
}

<< Previous: Getting Started – Next: List of Methods for Public Customers >>

Print Friendly, PDF & Email