Java code exampleIn 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 inWSDLURL 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 10minutesSendRequest 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 exampleIn the PHP implementation a toolkit called NuSOAP version 0.6.7 (download forfree 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 invokingservice$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 exampleIn the Microsoft implementation using VBScript, the SOAP Toolkit 3.0 has beenused together with Windows Script Host Version 5.6 (cscript.exe). The SOAPToolkit can be downloaded from http://www.microsoft.com/downloads/.Option ExplicitOn Error Resume NextDim SoapClient ’ As SoapClient30Dim SendReturn ’ As IXMLDOMSelectionDim Dom ’ As New DOMDocument3Dim Request ’ As IXMLDOMNodeListSet 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 propertySoapClient.ClientProperty("ServerHTTPRequest") = True’ Change endpoint URL if other than service location specified in WSDLSoapClient.ConnectorProperty("EndPointURL") = "hhttp://host:port/path"’ Set read timeout to 10 minutesSoapClient.ConnectorProperty("Timeout") = 60*10*1000Set Dom = CreateObject("Msxml2.DOMDocument")’ Use this as container when creating the requestSet Dom.documentElement = Dom.createElement("tempDoc")’ Add parametersCall 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 serviceSet SendReturn = SoapClient.send(Request)If err <> 0 Thenwscript.echo "Error: "wscript.echo err.descriptionwscript.echo "faultcode=" + Soapclient.faultcodewscript.echo "faultstring=" + Soapclient.faultstringwscript.echo "faultactor=" + Soapclient.faultactorwscript.echo "detail=" + Soapclient.detailElse’ 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 valueFunction GetResponseParam(oDom, strKey)Dim jFor j = 0 to oDom.lengthIf oDom.item(j).nodeName = strKey ThenGetResponseParam = oDom.item(j).textExit FunctionEnd IfNextEnd Function’ Parse a DOM and print all node names and their valuesSub PrintResponseParams(oDom)Dim jFor j = 0 to oDom.lengthwscript.echo oDom.item(j).nodeName & ": " & oDom.item(j).textNextEnd Sub’ Append a child element to a DOM, with specified name and value.Sub AppendChildElement(byRef oDom, strElementName, strElementValue)Dim ElmSet Elm = oDom.createNode(1, strElementName,"http://www.ipx.com/api/services/smsapi51/types")Elm.text = strElementValueoDom.documentElement.appendChild ElmEnd SubPERL code exampleIn the PERL implementation a toolkit called SOAP::Lite version 0.55 (downloadfor 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 minutesmy $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_dataSOAP::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 resultsif ($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 exampleThis .NET example is written in C# using Microsoft .NET Framework 1.1. Add thetarget web service WSDL as web reference and .NET will generate the necessarystub 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 inWSDLaService.Url = "http://host:port/path";aService.Timeout = 60*10*1000; // Set read timeout to 10 minutesSendResponse 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);}
Tuesday, December 30, 2008
Other languages and text messaging
Labels:
rails,
ruby on rails,
sms,
sms on rails,
text messaging
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment