Data Collection - Web Service

Data Collection has a built-in Web Service that can be used to get information from the data collection engine. 

RspService

Methods

GetAnswers(string queryString, List<string> quesItems) 

Description

Gets answers from the supplied question items for the given query string.
Usage: for ongoing test and live interviews.

GetAnswersFromRspId(string rspId, List<string> quesItems) 

Description

Gets answers from the supplied question items for the given respondent. 
Usage: for ongoing live interviews or finished interviews when the respondent ID is known. 

Example (jQuery) 
// Array of question items, with or without "\" var qItems = new Array(); qItems[0] = "Label1.a";   //single qItems[1] = "Label2.a";   //multi qItems[2] = "Label4.a";   //single with open row qItems[3] = "Label5.a.2"; //multi grid qItems[4] = "Label6.a.2"; //numeric qItems[5] = "Label7.a.2"; //duration (note: result will be in minutes) qItems[6] = "non-ex.a";   //non-existent qItems[7] = "Label1.a.1"; //invalid address  // Function parameters, json formatted // Note that parameter names are case sensitive   // -- Method 1, query string (live or test)<br> // var qs = window.location.search; //Query string // var sData = JSON.stringify({ queryString: qs, quesItems: qItems }); // Stay on the same DC server, required if this is a test interview // var serviceUrl = "Services/RspService.asmx/GetAnswers";  // Any DC server, does not work with test inteviews // var serviceUrl = "dc.miprocloud.net/dcwebengine/Services/RspService.asmx/GetAnswers";   // Or:  // -- Method 2, respondent ID is known<br> var rId = $("#mi_rspid").val(); //Respondent ID var sData = JSON.stringify({ rspId: rId, quesItems: qItems }); // If we want to stay on the same DC server var serviceUrl = "Services/RspService.asmx/GetAnswersFromRspId";  // If we want to use any DC server // var serviceUrl = "dc.miprocloud.net/dcwebengine/Services/RspService.asmx/GetAnswersFromRspId";   $.ajax({ 	type: 'POST', 	url: serviceUrl, 	data: sData,  	dataType: 'json', 	contentType: 'application/json; charset=utf-8', 	success: function(response) { 		// Response is wrapped within a "d" object (Asp.Net security), skip this 		handleResponse(response.hasOwnProperty("d") ? response.d : response); 	}, 	error: function(error) { 		console.log("Error" + error); 	} });  function handleResponse(obj)  { 	// Do something with the json obj here...  	// if (obj.Success) { 	//  ... 	// } 	// Debug example, display json obj as a formatted string in console: 	console.log(JSON.stringify(obj, null, 2)); } 

The following will be  written to the console:      

{   "Success": true,   "Message": "",   "QuesItemAnswers": [     {       "Address": "Label1.a",       "ItemType": "n",       "ItemFound": true,       "Message": "",       "IsAsked": true,       "IsAnswered": true,       "Answers": [         {           "Code": "2",           "IsOpen": false,           "IsQuant": false,           "AnswerText": ""         }       ]     },     {       "Address": "Label2.a",       "ItemType": "m",       "ItemFound": true,       "Message": "",       "IsAsked": true,       "IsAnswered": true,       "Answers": [         {           "Code": "2",           "IsOpen": false,           "IsQuant": false,           "AnswerText": ""         }       ]     },     {       "Address": "Label4.a",       "ItemType": "n",       "ItemFound": true,       "Message": "",       "IsAsked": true,       "IsAnswered": true,       "Answers": [         {           "Code": "4",           "IsOpen": true,           "IsQuant": false,           "AnswerText": "I'm an open answer"         }       ]     },     {       "Address": "Label5.a.2",       "ItemType": "rm",       "ItemFound": true,       "Message": "",       "IsAsked": true,       "IsAnswered": true,       "Answers": [         {           "Code": "1",           "IsOpen": false,           "IsQuant": false,           "AnswerText": ""         },         {           "Code": "2",           "IsOpen": false,           "IsQuant": false,           "AnswerText": ""         }       ]     },     {       "Address": "Label6.a.2",       "ItemType": "f",       "ItemFound": true,       "Message": "",       "IsAsked": true,       "IsAnswered": true,       "Answers": [         {           "Code": "",           "IsOpen": false,           "IsQuant": true,           "AnswerText": "2.2"         }       ]     },     {       "Address": "Label7.a.2",       "ItemType": "h",       "ItemFound": true,       "Message": "",       "IsAsked": true,       "IsAnswered": true,       "Answers": [         {           "Code": "",           "IsOpen": false,           "IsQuant": true,           "AnswerText": "184"         }       ]     },     {       "Address": "non-ex.a",       "ItemType": "",       "ItemFound": false,       "Message": "Question with qno 'non-ex' not found",       "IsAsked": false,       "IsAnswered": false,       "Answers": []     },     {       "Address": "Label1.a.1",       "ItemType": "n",       "ItemFound": false,       "Message": "Invalid reference to a single/multi question",       "IsAsked": false,       "IsAnswered": false,       "Answers": []     }   ] } 

C# Classes

public class AnswerResult {     /// <summary>     /// Value indicating whether the processing was successful.     /// </summary>     public bool Success;     /// <summary>     /// Error message, set when the processing was not successful.     /// </summary>     public string Message = string.Empty;     /// <summary>     /// Collection of question item answers     /// </summary>     public List<QuesItemAnswer> QuesItemAnswers = new List<QuesItemAnswer>();     /// <summary>     /// Constructor     /// </summary>     protected internal AnswerResult()     {     } } public class QuesItemAnswer {     /// <summary>     /// Address of the question item     /// </summary>     public string Address = string.Empty;     /// <summary>     /// Question item type, i.e. the sub question type     /// </summary>     public string ItemType = string.Empty;     /// <summary>     /// Value indicating whether the requested item was found.     /// </summary>     public bool ItemFound;     /// <summary>     /// Error message, set when the requested item was not found.     /// </summary>     public string Message = string.Empty;     /// <summary>     /// Value indicating whether the requested item was asked.     /// </summary>     public bool IsAsked;     /// <summary>     /// Value indicating whether the requested item was answered.     /// </summary>     public bool IsAnswered;     /// <summary>     /// Collection of answers     /// </summary>     public List<Answer> Answers = new List<Answer>();     /// <summary>     /// Constructor     /// </summary>     protected internal QuesItemAnswer()     {     } } public class Answer {     /// <summary>     /// Answer code as string, set when this is a categorical answer.     /// </summary>     public string Code = string.Empty;     /// <summary>     /// Value indicating whether this is an open ended answer.     /// </summary>     public bool IsOpen;     /// <summary>     /// Value indicating whether this is a quantitative answer.     /// </summary>     public bool IsQuant;     /// <summary>     /// Answer as string, set when this is a quantitative or an open ended answer.     /// </summary>     public string AnswerText = string.Empty;     /// <summary>     /// Constructor     /// </summary>     protected internal Answer()     {     } }