Tuesday, December 30, 2008

Other languages and text messaging

Java code example

In the Java implementation the IPX java API (api-smsapi50.jar) and Axis 1.1 have been used together with J2SE 1.4.2.

try {
// If using proxy
// System.setProperty("http.proxyHost", "proxyhost");
// System.setProperty("http.proxyPort", "8080");
// Change endpoint URL if other than service location specified in
WSDL
URL aPortUrl = new URL("http://host:port/path");
SmsApiServiceLocator aLocator = new SmsApiServiceLocator();
SmsApiPort anSmApi = aLocator.getSmsApi51(aPortUrl);
((Stub) anSmApi).setTimeout(10*60*1000); // Set read timeout to 10
minutes
SendRequest aRequest = new SendRequest();
aRequest.setCorrelationId("corrID");
aRequest.setOriginatingAddress("72160");
aRequest.setOriginatorTON(0);
aRequest.setDestinationAddress("msisdn");
aRequest.setUserData("Test message");
aRequest.setUserDataHeader("#NULL#");
aRequest.setDCS(-1);
aRequest.setPID(-1);
aRequest.setRelativeValidityTime(-1);
aRequest.setDeliveryTime("#NULL#");
aRequest.setStatusReportFlags(0);
aRequest.setAccountName("#NULL#");
aRequest.setTariffClass("EUR0");
aRequest.setVAT(-1);
aRequest.setReferenceId("#NULL#");
aRequest.setContentCategory("#NULL#");
aRequest.setContentMetaData("#NULL#");
aRequest.setUsername("username");
aRequest.setPassword("password");
SendResponse aResult = anSmApi.send(aRequest);
// System.out.println("Response: " + aResponse);
System.out.println("Result: correlationId: "
+ aResult.getCorrelationId());
System.out.println("Result: messageId: "
+ aResult.getMessageId());
System.out.println("Result: responseCode: "
+ aResult.getResponseCode());
System.out.println("Result: responseMessage: "
+ aResult.getResponseMessage());
System.out.println("Result: temporaryError: "
+ aResult.isTemporaryError());
} catch (Exception e) {
e.printStackTrace();
}

PHP code example

In the PHP implementation a toolkit called NuSOAP version 0.6.7 (download for
free at http://dietrich.ganx4.com/nusoap/) has been used together with PHP 4.3.5.

require_once(’../nusoap.php’);
# Load wsdl and reuse the client instance or set all parameters when invoking
service
$soapclient = new soapclient(’http://host:port/path?wsdl’,true);
# If using proxy
# $soapclient = new soapclient(’http://host:port/path?wsdl’,true,
# ’proxyhost’, 8080);
# print_r($soapclient->getOperationData(’send’));
# Change endpoint URL if other than service location specified in WSDL
$soapclient->operations[’send’][’endpoint’] = ’http://host:port/path’;
# print_r($soapclient->getOperationData(’send’));
$soapclient->response_timeout = 600; // Set read timeout to 10 minutes
$params = array(
’correlationId’ => ’corrID’,
’originatingAddress’ => ’72160’,
’originatorTON’ => ’0’,
’destinationAddress’ => ’msisdn’,
’userData’ => ’Test message’,
’userDataHeader’ => ’#NULL#’,
’DCS’ => ’-1’,
’PID’ => ’-1’,
’relativeValidityTime’ => ’-1’,
’deliveryTime’ => ’#NULL#’,
’statusReportFlags’ => ’0’,
’accountName’ => ’#NULL#’,
’tariffClass’ => ’EUR0’,
’VAT’ => ’-1’,
’referenceId’ => ’#NULL#’,
’contentCategory’ => ’#NULL#’,
’contentMetaData’ => ’#NULL#’,
’username’ => ’username’,
’password’ => ’password’);
# print "Request:";
# print_r($params);
$outparams = $soapclient->call(’send’,array(’request’ => $params));
# print "Result:";
# print_r($outparams);
if ($soapclient->getError() != null) {
print "Error: ";
print $soapclient->getError()."\n";
}
else {
print "Result: correlationId: ".$outparams[’correlationId’]."\n";
print "Result: messageId: ".$outparams[’messageId’]."\n";
print "Result: responseCode: ".$outparams[’responseCode’]."\n";
print "Result: responseCode: ".$outparams[’reasonCode’]."\n";
print "Result: responseMessage: ".$outparams[’responseMessage’]."\n";
}
?>

VBScript code example

In the Microsoft implementation using VBScript, the SOAP Toolkit 3.0 has been
used together with Windows Script Host Version 5.6 (cscript.exe). The SOAP
Toolkit can be downloaded from http://www.microsoft.com/downloads/.

Option Explicit
On Error Resume Next
Dim SoapClient ’ As SoapClient30
Dim SendReturn ’ As IXMLDOMSelection
Dim Dom ’ As New DOMDocument3
Dim Request ’ As IXMLDOMNodeList
Set Soapclient = CreateObject("MSSOAP.SoapClient30")
’ In case of Soap Toolkit 2.0
’ Set Soapclient = CreateObject("MSSOAP.SoapClient")
Call SoapClient.mssoapinit("hhttp://host:port/path?wsdl")
’ If using proxy
’ SoapClient.ConnectorProperty("ProxyServer") = "proxyhost:8080"
’ See SOAP Toolkit API for info about this property
SoapClient.ClientProperty("ServerHTTPRequest") = True
’ Change endpoint URL if other than service location specified in WSDL
SoapClient.ConnectorProperty("EndPointURL") = "hhttp://host:port/path"
’ Set read timeout to 10 minutes
SoapClient.ConnectorProperty("Timeout") = 60*10*1000
Set Dom = CreateObject("Msxml2.DOMDocument")
’ Use this as container when creating the request
Set Dom.documentElement = Dom.createElement("tempDoc")
’ Add parameters
Call AppendChildElement(Dom, "correlationId", "corrID")
Call AppendChildElement(Dom, "originatingAddress", "72160")
Call AppendChildElement(Dom, "originatorTON", "0")
Call AppendChildElement(Dom, "destinationAddress", "msisdn")
Call AppendChildElement(Dom, "userData", "Test message")
Call AppendChildElement(Dom, "userDataHeader", "#NULL#")
Call AppendChildElement(Dom, "DCS", "-1")
Call AppendChildElement(Dom, "PID", "-1")
Call AppendChildElement(Dom, "relativeValidityTime", "-1")
Call AppendChildElement(Dom, "deliveryTime", "#NULL#")
Call AppendChildElement(Dom, "statusReportFlags", "0")
Call AppendChildElement(Dom, "accountName", "#NULL#")
Call AppendChildElement(Dom, "tariffClass", "EUR0")
Call AppendChildElement(Dom, "VAT", "-1")
Call AppendChildElement(Dom, "referenceId", "#NULL#")
Call AppendChildElement(Dom, "contentCategory", "#NULL#")
Call AppendChildElement(Dom, "contentMetaData", "#NULL#")
Call AppendChildElement(Dom, "username", "username")
Call AppendChildElement(Dom, "password", "password")
Set Request = Dom.documentElement.childNodes
’ Invoke web service
Set SendReturn = SoapClient.send(Request)
If err <> 0 Then
wscript.echo "Error: "
wscript.echo err.description
wscript.echo "faultcode=" + Soapclient.faultcode
wscript.echo "faultstring=" + Soapclient.faultstring
wscript.echo "faultactor=" + Soapclient.faultactor
wscript.echo "detail=" + Soapclient.detail
Else
’ Call PrintResponseParams(SendReturn)
wscript.echo "Result: correlationId " & GetResponseParam(SendReturn,
"correlationId")
wscript.echo "Result: messageId: " & GetResponseParam(SendReturn, "messageId")
wscript.echo "Result: responseCode: " & GetResponseParam(SendReturn,
"responseCode")
wscript.echo "Result: reasonCode: " & GetResponseParam(SendReturn,
"reasonCode")
wscript.echo "Result: responseMessage: " & GetResponseParam(SendReturn,
"responseMessage")
End If
’ Helper functions
’ Parse a DOM for a specific element and return its value
Function GetResponseParam(oDom, strKey)
Dim j
For j = 0 to oDom.length
If oDom.item(j).nodeName = strKey Then
GetResponseParam = oDom.item(j).text
Exit Function
End If
Next
End Function
’ Parse a DOM and print all node names and their values
Sub PrintResponseParams(oDom)
Dim j
For j = 0 to oDom.length
wscript.echo oDom.item(j).nodeName & ": " & oDom.item(j).text
Next
End Sub
’ Append a child element to a DOM, with specified name and value.
Sub AppendChildElement(byRef oDom, strElementName, strElementValue)
Dim Elm
Set Elm = oDom.createNode(1, strElementName,
"http://www.ipx.com/api/services/smsapi51/types")
Elm.text = strElementValue
oDom.documentElement.appendChild Elm
End Sub

PERL code example

In the PERL implementation a toolkit called SOAP::Lite version 0.55 (download
for free at http://www.soaplite.com/) has been used together with ActivePerl-
5.8.3.809.

#!perl -w
# If using proxy
# $ENV{HTTP_proxy} = "http://proxyhost:8080/";
# use SOAP::Lite +trace => ’debug’;
use SOAP::Lite;
# Target URL. Set read timeout to 10 minutes
my $client = SOAP::Lite ->proxy(’http://host:port/path’, timeout => 600);
# Force the SDK not to guess types of the SOAP elements
$client->autotype(0);
my @parameters =
(SOAP::Data->name(correlationId => ’correlationId’)->value(’corrID’),
SOAP::Data->name(originatingAddress => ’originatingAddress’)->value(’72160’),
SOAP::Data->name(originatorTON => ’originatorTON’)->value(’0’),
SOAP::Data->name(destinationAddress => ’destinationAddress’)->value(’msisdn’),
# Note: the toolkit does not automatically escape XML unsafe characters,
# use encode_data
SOAP::Data->name(userData => ’userData’)
->value(SOAP::Utils::encode_data(’Test message’)),
SOAP::Data->name(userDataHeader => ’userDataHeader’)->value(’#NULL#’),
SOAP::Data->name(DCS => ’DCS’)->value(’-1’),
SOAP::Data->name(PID => ’PID’)->value(’-1’),
SOAP::Data->name(relativeValidityTime => ’relativeValidityTime’)->value(’-1’),
SOAP::Data->name(deliveryTime => ’deliveryTime’)->value(’#NULL#’),
SOAP::Data->name(statusReportFlags => ’statusReportFlags’)->value(’0’),
SOAP::Data->name(accountName => ’accountName’)->value(’#NULL#’),
SOAP::Data->name(tariffClass => ’tariffClass’)->value(’EUR0’),
SOAP::Data->name(VAT => ’VAT’)->value(’-1’),
SOAP::Data->name(referenceId => ’referenceId’)->value(’#NULL#’),
SOAP::Data->name(contentCategory => ’contentCategory’)->value(’#NULL#’),
SOAP::Data->name(contentMetaData => ’contentMetaData’)->value(’#NULL#’),
SOAP::Data->name(username => ’username’)->value(’username’),
SOAP::Data->name(password => ’password’)->value(’password’),
);
# send request and retrieve information (RPC like document style service)
my $body = SOAP::Data->name(’SendRequest’) ->
attr({xmlns => ’http://www.ipx.com/api/services/smsapi51/types’});
$result = $client->call($body => @parameters);
# print all results
if ($result->fault)
{
print "Error: ", $result->faultstring, "\n";
}
else
{
print "Result: correlationId: ", $result-
>valueof(’//SendResponse/correlationId’), "\n";
print "Result: messageId: ", $result->valueof(’//SendResponse/messageId’),
"\n";
print "Result: responseCode: ", $result-
>valueof(’//SendResponse/responseCode’), "\n";
print "Result: responseCode: ", $result->valueof(’//SendResponse/reasonCode’),
"\n";
print "Result: responseMessage: ", $result-
>valueof(’//SendResponse/responseMessage’), "\n";
}

.NET code example

This .NET example is written in C# using Microsoft .NET Framework 1.1. Add the
target web service WSDL as web reference and .NET will generate the necessary
stub code for the client side.

try
{
SmsApiService aService = new SmsApiService();
SendRequest aRequest = new SendRequest();
aRequest.correlationId = "corrId";
aRequest.originatingAddress = "72160";
aRequest.originatorTON = 0;
aRequest.destinationAddress = "msisdn";
aRequest.userData = "Test message";
aRequest.userDataHeader = "#NULL#";
aRequest.DCS = -1;
aRequest.PID = -1;
aRequest.relativeValidityTime = -1;
aRequest.deliveryTime = "#NULL#";
aRequest.statusReportFlags = -1;
aRequest.accountName = "#NULL#";
aRequest.tariffClass = "EUR0";
aRequest.VAT = -1;
aRequest.referenceId = "#NULL#";
aRequest.contentCategory = "#NULL#";
aRequest.contentMetaData = "#NULL#";
aRequest.username = "username";
aRequest.password = "password";
// If using proxy
// aService.Proxy = new System.Net.WebProxy("proxyhost", 8080);
// Change endpoint URL if other than service location specified in
WSDL
aService.Url = "http://host:port/path";
aService.Timeout = 60*10*1000; // Set read timeout to 10 minutes
SendResponse aResult = aService.send(aRequest);
Console.Out.WriteLine("Result: correlationId: " +
aResult.correlationId);
Console.Out.WriteLine("Result: messageId: " + aResult.messageId);
Console.Out.WriteLine("Result: responseCode: " +
aResult.responseCode);
Console.Out.WriteLine("Result: reasonCode: " + aResult.reasonCode);
Console.Out.WriteLine("Result: responseMessage: " +
aResult.responseMessage);
}
catch (Exception e)
{
Console.Out.WriteLine("Exception: " + e);
}

No comments: