Click here to Skip to main content
15,881,859 members
Articles / Web Development / ASP.NET
Tip/Trick

Web-based Data Access Object

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
3 Apr 2013CPOL3 min read 16.9K   165   4   3
Generalize to access data in a database via HTTP
Introduction 

We can not access data in a database for Database Provider, when there is security policy or a database is connected on WAN. Take mobile applications development for example. In this case, we can not use Database Provider. Generally after making XML-based data on a web server, the data is sent to client-side device via HTTP or HTTPS. And a mobile application on client-side device parse the data. It is not generalized to make and parse XML-based data. It bother us and we spend too much time. At this article, I will generalize to access data in a database via HTTP. 

Web-based Data Access Object(Web-DAO) means to access data in a database for Web Services instead of Database Provider like Oracle Client. Web Services of ASP.Net provides a method to make and parse XML-based data easily. And the class System.Data.DataTable of .NET Framework is useful to deal with data of Record Set form. It is the following diagram how to access data in a database via Web Services of ASP.NET. 

 

Background      

First up, we have to know how to open Web Services and for client device how to access to Web Services. Please refer following articles. First article described what is Web Service in ASP.NET and how to open in detail. But you will have to study about Web service of ASP.Net more if you want to publish real Web Service for Web-DAO. Second article described that how Managed-Code application of client device access to Web Services.  

Using the code   

1. Open Web Service for Web-DAO in ASP.NET    

We must set Web Service of ASP.NET up for Web-DAO. Web-DAO access data in a database for Database Provider. Because Oracle is used as database at sample, you must input Oracle service name, user ID and password. Please open the C# file [WebDAO.asmx] of project [WSWebDAO] and input your information of Oracle database like the following.  

static string strDataSource = "DataSource";
static string strUserID = "UserID";
static string strPassword = "Password";

Please run Web Service for Web-DAO. And then ASP.NET Development Server will be run automatically.  If you see the following picture, Web Service for Web-DAO is oepned correctly.  

 

We can check to run correctly r not. Please click the link [GetRecordSet] and input the SQL [select sysdate from dual] on the textbox [strSQL].  You will be able to see system time of Oracle server.    

   

2.  Access data in a database via Web Service for Web-DAO 

Please run Managed-Code application of project [WebDAOTestManaged]. Input URL of the Web Service on Textbox[tbWebAddress]. It is URL of ASP.Net Development  Server (in this case, http://localhost:3342). Please Input SQL Query on Textbox[tbGetDataRecord].  You will be able to get result data.  

   

Conclusion

I described how to generalize to access data in a database via HTTP. Web-DAO is the method to access data in a database for Web Services instead of Database Provider. When I developed managed-code application via Web-DAO, we don't need to install Oracle Client and install the application easily.  When I add to access another on mobile application I save too much time. We need to remember two thing. First, Web-DAO get all data at one time even though the volume of data is big. So we need to consider access speed and time. Second, We consider how to maintain security, because any body can access data in a database if Web-DAO is opened on WAN. 

Next Time 

Next time, I will descried how to access on Unmanaged-Code application like unmanaged C++. And I will introduce how to access data in a database via Web-DAO on iOS and Android System.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Korea (Republic of) Korea (Republic of)
Software Engineer.

Comments and Discussions

 
GeneralMissing download Pin
Smitha Nishant3-Apr-13 6:29
protectorSmitha Nishant3-Apr-13 6:29 
GeneralRe: Missing download Pin
In the Face of God3-Apr-13 6:58
In the Face of God3-Apr-13 6:58 
GeneralRe: Missing download Pin
Smitha Nishant3-Apr-13 8:38
protectorSmitha Nishant3-Apr-13 8:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.