Difference between revisions of "DCS Web Service"
m (→How to use) |
|||
Line 8: | Line 8: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
− | var dcsId = 4246; | + | //-------CONFIGURATION-------------------- |
− | var columns = "'UserId','FirstName','DisabledDate','DeletedDate','Amt','Kommune_gammel','Region | + | var dcsId = 4246;//Primary key of the DCS |
+ | var columns = "'UserId', 'FirstName', 'DisabledDate', 'DeletedDate', 'Amt', 'Kommune_gammel', 'Region', 'Postnummer', 'Boligtype'";//selected columns | ||
+ | |||
var username = "maimai";//your username to login to Catglobe system | var username = "maimai";//your username to login to Catglobe system | ||
var password = "cg";//your password | var password = "cg";//your password | ||
var rootUrl = 'http://localhost/supernova';//replace this with your site, ex: http://mycatinet.catglobe.com | 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 webMethod = rootUrl + '/DataModule/DataCache/WebService/DCSWebService.asmx/GetDCSData'; | ||
− | var loginPage = rootUrl + '/Login.aspx?u= | + | var loginPage = rootUrl + '/Login.aspx?u='+username+'&p='+password; |
var parameters = "{'dcsId':" + dcsId + ",'columns':[" + columns + "]}";//JSON format | var parameters = "{'dcsId':" + dcsId + ",'columns':[" + columns + "]}";//JSON format | ||
Revision as of 03:24, 2 June 2009
Contents
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.
//-------CONFIGURATION--------------------
var dcsId = 4246;//Primary key of the DCS
var columns = "'UserId', 'FirstName', 'DisabledDate', 'DeletedDate', 'Amt', 'Kommune_gammel', 'Region', 'Postnummer', 'Boligtype'";//selected columns
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='+username+'&p='+password;
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>