DCS Web Service

From Catglobe Wiki
Revision as of 03:20, 2 June 2009 by Catglobe (talk | contribs)
Jump to: navigation, search

Introduction

The original reason for creating DCS web service was to retrieve data answered in a questionnaire and display them on a Portal element.

How to use

The simplest way is to use ajax request using jquery.

If the request is not made from an internal page inside Catglobe system, we need to make a dummy login first, then make the call to the web service.

var dcsId = 4246;
var columns = "'UserId','FirstName','DisabledDate','DeletedDate','Amt','Kommune_gammel','Region','Kommune','Postnummer','Boligtype'";
var username = "maimai";//your username to login to Catglobe system
var password = "cg";//your password
var rootUrl = 'http://localhost/supernova';//replace this with your site, ex: http://mycatinet.catglobe.com
var webMethod = rootUrl + '/DataModule/DataCache/WebService/DCSWebService.asmx/GetDCSData';
var loginPage = rootUrl + '/Login.aspx?u=maimai&p=cg';//
var parameters = "{'dcsId':" + dcsId + ",'columns':[" + columns + "]}";//JSON format

$.ajax({
   type: "POST",
   url: loginPage,
   success: function(msg) 
   {
      //login successfully, now call the web service      
      $.ajax({
         type: "POST",
         url: webMethod,
         data: parameters,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function(msg) 
         {
            var dataTable = eval(msg.d);
            //Code of using the data table here
         },
         error: function(e) 
         {         
            //error when connecting to the web service
         }
      });
   },
   error: function(e) 
   {
      //error when trying to login
   }   
});

Limitation

There is a limit of data retrieval defined by JavaScriptSerializer.maxJsonLength, which is 4 MB Unicode characters as default. If the data retrieval is higher than this, an error will be returned in the onFailFunction: "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property"

This can be fixed by updating the web config file:

<system.web.extensions>    
<scripting>      
<webServices>        
<jsonSerialization maxJsonLength="500000">        
</jsonSerialization>      
</webServices>    
</scripting>
</system.web.extensions>

Examples

Display a questionnaire's answers in real time