Click here to Skip to main content
Licence 
First Posted 19 Apr 2004
Views 30,710
Bookmarked 10 times

Make 'ToDo' system for multi-program complex system: Part 2

By | 19 Apr 2004 | Article
Make 'ToDo' system for multi-program complex system using ASP.NET & C#.

Introduction

In previous part, we made a simple WebService, that allows storing and retrieving simple messages. In this step, we make a simple stand-alone Windows Forms client, for this service.

Part II.

Client-side

Step 1 : Skeleton project

First, we make a skeleton project for the client app. This is a simple Windows Application project with two Form delivered classes:

  • ViewForm - form for viewing posted messages
  • NewMessageForm - form for posting a new message

ViewForm

NewMessageForm

NewMessageForm creating can be completed with Forms designer, in three steps:

  • setting DialogResult property for 'Post' button to OK;
  • setting DialogResult property for 'Cancel' button to Cancel;
  • setting Midifiers property for TextBox to public;

ViewForm class demands more complex code.

Step 2 : Reading data from Service

Next step is to read posted messages from the webservice. In this step of developing, I added this code to the ButtonClick event of 'Update' button. In future, this code will be called for complex tasks.

private void BtnUpdate_Click(object sender, System.EventArgs e)
{
    XmlDocument xdoc = new XmlDocument();
    msgView.Items.Clear();
            
    try
    {
        xdoc.Load("http://dbserv:88/todo/log.asmx/GetLog?");

        XmlNodeList nodes = xdoc.SelectNodes("/log/message");
        foreach (XmlNode node in nodes)
        {
            try
            {
                ListViewItem item = 
                  new ListViewItem(node.Attributes["posted"].InnerText);
                item.SubItems.Add(node.InnerText);
                msgView.Items.Add(item);
            }
            catch (Exception)
            {
                ListViewItem item = new ListViewItem("Corupted!!!");
                msgView.Items.Add(item);
            }
        }
    }
    catch (Exception ex)
    {
        ListViewItem item = new ListViewItem("Failed");
        item.SubItems.Add(ex.Message);
        msgView.Items.Add(item);
    }
}

First two lines of function code initialize empty XmlDocument instance and clear all stored items from ListView control.

In first try...catch block, load stored messages from server (XmlDocument.Load()) and retrieve list of nodes containing messages' data (XmlDocument.SelectNodes()). foreach block browses items in result collection of XmlNode objects. Nested try...catch block creates new ListViewItem object for each message, parses XmlNode object for message data, and stores it in ListViewItem object.

Step 3 : Post new messages to Service

Next step is to implement ability to post new messages from client to server. Code for this is placed in ButtonClick event handler for button 'Post'.

private void NewPost_Click(object sender, System.EventArgs e)
{
    NewMessageForm dlg = new NewMessageForm();
    if (dlg.ShowDialog() == DialogResult.OK)
    {
        System.Collections.Specialized.NameValueCollection parms = 
           new System.Collections.Specialized.NameValueCollection(1);
        parms.Add("message", dlg.msgText.Text);
        WebClient req = new WebClient();
        req.UploadValues("http://dbserv:88/todo/log.asmx/PostMessage", parms);
    }
    dlg.Dispose();
}

If you have some questions about this function, post it in the comments section of this article (for me, it is very simple code).

Using the code

Install and use code

This is all for this step. In result, we have a simple Stand-Alone client program that allows us to interact with the server.

To test this code, download the demo project. Change 'http://dbserv:88/togo/' in source to your WebApp home URL and build solution.

Copy code library for WEB application located in web_bin directory to bin directory of your Web application. Create log.asmx file in root folder of your web application. log.asmx file must contain only this row:

<%@ WebService language="C#" class="devel.Log" %>

Client program is located in the bin folder.

History

Part I of this article can be located here.

P.S

Post in comments/questions about code parts. I plan to update article description based on your questions.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Mad__

Web Developer

Ukraine Ukraine

Member

Developing software for Civilian aviation and Meteorogical offices.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 20 Apr 2004
Article Copyright 2004 by Mad__
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid