Web Services (WS) are now a reality for many enterprises and have moved beyond the hype stage. Many enterprises have built Web Services pilot projects, proving that WS can reduce integration and development cost substantially and enhance customer and supplier integration. This article will walk you through the Web Service development process using PHP, MySQL, VB, NuSOAP or XML-RPC. Before going further, you can download and install the client (the example, discussed in this article) from here and start playing with it for a better understanding the topics of this article.
Web Services for K-12 Education Systems - Walkthrough Example (Page 3 of 4 )
I. Start a VB project with Visual Studio, from project->Reference check Microsoft SOAP Type Library V3.0. Create a SOAP class Listing 1. We will use this class to create SOAP messages.
Private Sub GetDataOnConnect
() ‘ On connect display list of activities to choose Dim k As String Dim soap As SOAPSender Set soap = New SOAPSender soap.BeginBodyPart "fnWebService", http://az.homeunix.com/as/k12.php ‘function name soap.BeginElement " ActivityTitle ", "" soap.WriteText ActivityTitle.text soap.EndElement soap.EndBodyPart soap.SoapAction = " http://az.homeunix.com/as/k12.php " ‘ Web Service end point soap.ServiceUrl = " http://az.homeunix.com/as/k12.php " soap.Send DisplayData k End Sub
Private Sub DisplayData(ByVal response As String) On Error GoTo L1 Dim mTemp As String Dim doc As MSXML2.DOMDocument Set doc = New MSXML2.DOMDocument If doc.loadXML(response) Then ‘ Parse the response text mTemp = doc.selectSingleNode("//noname").text WebBrowser1.Visible = True End If Else MsgBox "Failed to load the response text: " & vbCrLf & response End If Exit Sub L1: MsgBox "Content for this activity title not available now, please check back later.", vbInformation, "Empty Activity" End Sub
II. Above code will parse SOAP envelope and display list of available (or subscribed) activities as soon as it connects to Web Service. Server:
<?php require_once('nusoap.php'); $s = new soap_server; $s->register('fnWebService'); function fnWebService ($name){
$link=mysql_connect('localhost','root','') or die (mysql_error()); mysql_select_db('db_webservice') or die (mysql_error()); $arrGrSub=explode('/', $name); $s=$arrGrSub[1]; $g=$arrGrSub[0]; $query="SELECT * FROM astabquestionentry ORDER BY qeLessonName";
if ($name!=''){ $query="SELECT * FROM astabquestionentry where qeLessonName='".$name."' LIMIT 1"; $result=mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $k='[ws:] http://localhost/ws.php?ln='.$row["qeLessonName"].'&r=NO&attempt='.$row["qeAttempt"].'&tq='.$row["qeTotalNumberOfQuestion"].'&ActType='.$row["qeActivity"]. '&strip=localhost&dbuser=root&dbpassword= &mydatabase=db_webservice'; //ws.php script is responsible to display items with description. This feature is not discussed in the article.
mysql_free_result($result); mysql_close($link); return $k; } } $result=mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $k=$k.$row["qeLessonName"].'nr'.' Description:'.strtolower(ucwords($row["qeObjective"] .' '.$row["qeSubSkill"])).' nr'; } mysql_free_result($result); mysql_close($link); return $k; } $s->service($HTTP_RAW_POST_DATA);