Questionmark's Open Assessment Platform

Using ASP to add participants to Perception through QMWISe

This page provides some example ASP code that can be used to link to your QMWISe APIs and create participants.

In the following example we use the SOAP Toolkit to make a connection to QMWISe.

The example ASP page can be downloaded from here (LINK NEEDED!).

To use the example place it on a web server that can contact your Perception installation via HTTP. The web server must also be capable of parsing ASP pages (for example, IIS). Install the SOAPToolKit on the server and create or place the example code in a web share.

Now browse to the example ASP file in a web browser. You should see something similar to the following:

The code:

<%
'
' This example deomonstrates how to use QMWise to:
' Add a participant to the Perception Particpant table
' Assign a participant to a group
' Provide a list of Perception groups
'
' This example uses the MS objects for building SOAP request. (The SOAP Toolkit must be installed)
' http://www.microsoft.com/downloads/details.aspx?FamilyId=C943C0DD-CEEC-4088-9753-86F052EC8450&displaylang=en
' MSSOAP.SoapSerializer30
' MSSOAP.HttpConnector30
' The MS XML DOM object is used to parse the SOAP responses
' Msxml2.DOMDocument
'
'
' There are 2 groups of functions in this source file. The first group contains functions that implement the exampe. These
' functions make calls into the second set of functions that provide functionality for creating the SOAP/QMWise request.
'
' Functions to implement the example
' Function CreateParticipant(sName, sFname, sLname, sPassword,sGroup)
' Sub AddGroup(sGroupName) - Not used in this example.
' Function GetGroupID(sGroup)
' Function GetGroupList()
'
' Functions the build SOAP/QMWise requests
' Function StartRequest(sFunction)
' Function AddRequestParameter(sParamName,sParamValue)
' Function PostRequest(bRet)
' Function QMWISERequest(sFunction, sParamName, sParamValue)
'
' Perception users are free to use or modify this code as the basis of their own
' software to call QMWISe. No warranty or support is provided.
'

'ON ERROR RESUME NEXT
'-------------------------------------------------------------
'-------------------------------------------------------------------

Dim END_POINT_URL ' Will contain the URL for the QMWise Web Service (located on your server)
Dim WRAPPER_ELEMENT_NAMESPACE
Dim BASE_SOAP_ACTION_URI
Dim BASE_URL
'
'
' Global objects used for constructing the SOAP request
Dim g_Serializer ' as MSSOAP.SoapSerializer30
Dim g_Connector ' as MSSOAP.HttpConnector30

'Setup the URL's need for the SOAP requests. This example assumes the QMWise service is runnign on the same domain as this webshare
BASE_URL = Request.ServerVariables("SERVER_NAME") ' "localhost"
END_POINT_URL = "http://" & BASE_URL & "/qmwise5/qmwise.asmx" 'Make sure the QMWISe webshare is correct for your installation
WRAPPER_ELEMENT_NAMESPACE = "http://" & BASE_URL & "/QMWISe/"
BASE_SOAP_ACTION_URI = "http://questionmark.com/QMWISe/"
'-------------------------------------------------------------
%>
<html>
<head>
<title>QMWise ASP Sample</title>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body bgcolor="#ffffff" text="#000000" >
<hr>
<p>This example demonstrates how to use QMWISe to:</p>
<ul>
<li>Add a participant to the Perception Participant table</li>
<li>Assign a participant to a group</li>
<li>Provide a list of Perception groups</li>
</ul>

<p>This example uses the MS objects for building SOAP request. (The <A
HREF="http://www.microsoft.com/downloads/details.aspx?
FamilyId=C943C0DD-CEEC-4088-9753-86F052EC8450&displaylang=en" TARGET="_NEW">SOAP Toolkit</A>
must be installed.) </p>
<ul>
<li>MSSOAP.SoapSerializer30</li>
<li>MSSOAP.HttpConnector30</li>
</ul>
<p>The MS XML DOM object is used to parse the SOAP responses</p>
<ul>
<li>Msxml2.DOMDocument</li>
</ul>
<p>Perception users are free to use or modify this code as the basis of their own
software to call QMWISe. No warranty or support is provided.</p>
<hr>
<form method="post" action="qmwisesample.asp" name="sampleform">
Participant Name (Participant_Name): <input type="text" name="idname"
value="<%=Request.Form("idname")%>"><i>(must be unique)</i><br>
First Name (First_Name): <input type="text" name="fname" value="<%
=Request.Form("fname")%>"><br>
Last Name (Last_Name): <input type="text" name="lname" value="<%
=Request.Form("lname")%>"><br>
Password (Password): <input type="text" name="password" value="<%
=Request.Form("password")%>"><br>
Group Name: <% GetGroupList()%><br><br>
<input type="submit" value="Add Participant" name="Submit">

<br>
<%

If Len(Request.Form("idname")) > 0 Then
Call CreateParticipant(Request.Form("idname"),Request.Form("fname"),Request.Form("lname"), Request.Form("password"),Request.Form("groupname"))
End If

%>
</form>
</body>
</html>

<%
'----------------------------------------------------------------
'
' Functions to implement the sample
'
Function CreateParticipant(sName, sFname, sLname, sPassword,sGroup)

Dim xmlObj
Dim xmlParticipant
Dim nodeGroup
Dim sGroupID
Dim sXmlResult

If Len(sGroup) > 0 Then
sGroupID = GetGroupID(sGroup)
' Response.Write sGroupID
End If

Set xmlObj = CreateObject("Msxml2.DOMDocument")

Call StartRequest("CreateParticipant")
g_Serializer.startElement "Participant", BASE_SOAP_ACTION_URI
Call AddRequestParameter("Participant_Name", sName)
Call AddRequestParameter("First_Name", sFname)
Call AddRequestParameter("Last_Name", sLname)
Call AddRequestParameter("Password", sPassword)
Call AddRequestParameter("Details_1", Request.QueryString("leanumber"))
'Build Group ID list
' If Len(sGroupID) > 0 Then
' g_Serializer.startElement "GroupIDList", BASE_SOAP_ACTION_URI
' Call AddRequestParameter("Group_ID", sGroupID)
' g_Serializer.endElement
' End If
g_Serializer.endElement
' Response.Write "Test"
sXmlResult = PostRequest(True) 'Submit the SOAP request, and request the xml response as a return value

xmlObj.loadXML(sXmlResult)

if Len(xmlObj.text) > 0 Then 'We've set the PostRequest function up to return an empty xml set if the function receives a fault
Response.Write "<br>Added Participant with ID of:<b> " & xmlObj.text & "</b>"

if Len(sGroupID) > 0 Then
Call StartRequest("AddGroupParticipantList")
Call AddRequestParameter("Group_ID", sGroupID)
g_Serializer.startElement "ParticipantIDList", BASE_SOAP_ACTION_URI
Call AddRequestParameter("Participant_ID", xmlObj.text)
g_Serializer.endElement
Call PostRequest(False)

End If

Else
Response.Write "<br>Unable to add participant, possibly already exists."
End If

End Function
'
' Not used in this example, but provided for additonal samples
'
Sub AddGroup(sGroupName)
Dim sID
sID = GetGroupID(sUserName & sCourse)
If Len(sID) = 0 Then
Call StartRequest("CreateGroup")
g_Serializer.startElement "Group", BASE_SOAP_ACTION_URI
Call AddRequestParameter("Group_Name", sUserName & sCourse)
Call AddRequestParameter("Parent_ID", "0")
Call AddRequestParameter("Account_Finish", "12/31/2010")
g_Serializer.endElement
Call PostRequest(False)
Else
Response.Write "<br>Group already exists"
End If

End Sub

'
' Returns the Group ID given a group name
'
Function GetGroupID(sGroup)

Dim xmlObj
Dim xmlGroup
Dim nodeGroup

Set xmlObj = CreateObject("Msxml2.DOMDocument")

xmlObj.loadXML(QMWISERequest("GetGroupByName", "Group_Name", sGroup))

If xmlObj.documentElement.childNodes.length > 0 Then
Set xmlGroup = xmlObj.documentElement.childNodes.Item(0)
GetGroupID = xmlGroup.text
Else
GetGroupID = ""
End If
End Function
'
' Builds a <select> list containing all the perception groups
'
Function GetGroupList()

Dim xmlObj
Dim xmlGroups
Dim nodeGroup
Dim i

Set xmlObj = CreateObject("Msxml2.DOMDocument")

Response.Write "<select name='groupname'>"
xmlObj.loadXML(QMWISERequest("GetGroupList", "", ""))
If Len(xmlObj.text) > 0 Then

For i = 0 To xmlObj.documentElement.childNodes.length - 1

Set nodeGroup = xmlObj.documentElement.childNodes.Item(i)

' Response.Write nodeParticipant.text
Set nodeGroupName = nodeGroup.selectSingleNode("Group_Name")

Response.Write "<option>" & nodeGroupName.text & "</option>"

Next

End If
Response.Write "</select>"

End Function

'
' Base functions for creation of SOAP requests to QMWise
'
'
'
'Create SOAP objects and intitialize them
'
Function StartRequest(sFunction)
Set g_Connector = CreateObject("MSSOAP.HttpConnector30")

g_Connector.Property("EndPointURL") = END_POINT_URL

g_Connector.Property("SoapAction") = BASE_SOAP_ACTION_URI & sFunction

g_Connector.BeginMessage

Set g_Serializer = CreateObject("MSSOAP.SoapSerializer30")
g_Serializer.Init g_Connector.InputStream

g_Serializer.startEnvelope
g_Serializer.startBody
g_Serializer.startElement sFunction, BASE_SOAP_ACTION_URI

End Function
'
' Add a parameter to the SOAP request, use this function for simple parameters, if you need
' to send complex parameters this function should not be used.
'
Function AddRequestParameter(sParamName,sParamValue)
' Response.Write sParamName
If Len(sParamName) > 0 Then
g_Serializer.startElement sParamName, BASE_SOAP_ACTION_URI
g_Serializer.writeString sParamValue
g_Serializer.endElement
End If
End Function
'
'Submit the SOAP request to the QMWise service and return the response
' if the call fails, this function returns an empty xml stream
'
' set bRet = True to return a value
'
Function PostRequest(bRet)

Dim Reader
g_Serializer.endElement
g_Serializer.endBody
g_Serializer.endEnvelope

g_Connector.EndMessage
Set Reader = CreateObject("MSSOAP.SoapReader30")
Reader.Load g_Connector.OutputStream

If Not Reader.Fault Is Nothing Then
Response.Write "<br><br>There was a fault:"
Response.Write Reader.faultstring.Text

If bRet Then
PostRequest = "<nodata/>"
End If
Set g_Serializer = Nothing
Set g_Connector = Nothing
Set Reader = Nothing
Exit Function

End If

If bRet Then
PostRequest = Reader.RPCResult.xml
End If

' Response.Write Reader.RPCResult.xml
Set g_Serializer = Nothing
Set g_Connector = Nothing
Set Reader = Nothing
End Function

'
' Send a simple SOAP request, only supports a single, simple parameter
'
Function QMWISERequest(sFunction, sParamName, sParamValue)
'Const BASE_SOAP_ACTION_URI = "http://tempuri.org/action/Calc."

Call StartRequest(sFunction)
Call AddRequestParameter(sParamName, sParamValue)
QMWISERequest = PostRequest(True)
End Function

%>