Difference between revisions of "DCS Web Service"

From Catglobe Wiki
Jump to: navigation, search
Line 1: Line 1:
 
==Introduction==
 
==Introduction==
 
The original reason for creating DCS web service was to retrieve data answered in a questionnaire and display them on a Portal element.
 
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 ==
+
== How to use ==
CatGlobe.Web.DataModule.DataCache.WebService.DCSWebService.GetDCSData(condition, onSuccessFunction, onFailFunction, element_context);
 
  
The condition xml should follow the format of:
+
The simplest way is to use [http://docs.jquery.com/Ajax/jQuery.ajax#options ajax request using jquery].
<source lang="xml" line="0">
+
 
<criteria dcs-id="1" top-N="1000" order-by-column="StartDate" order-type="desc">
+
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.
<column name="StartDate"></column>
+
 
<column name="Q25"></column>
+
<source lang="javascript">
<column name="BankName"></column>
+
var dcsId = 4246;
</criteria>
+
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
 +
  } 
 +
});
 
</source>
 
</source>
  

Revision as of 03:20, 2 June 2009

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