Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / C#
Article

hello, world - A primitive view of the state of the art

Rate me:
Please Sign up or sign in to vote.
4.85/5 (53 votes)
30 Apr 2004BSD22 min read 158.1K   1.1K   83   28
A revival of the CLI for .NET development.

The command-line in Windows XP

Introduction

This article is intended as a brief introduction to some of the more basic elements comprising .NET development. I will create and describe five simple applications for .NET, using nothing more than the .NET Framework SDK and a text editor. I will be playing off of the ever popular, "hello, world" theme. The language that I will be using in the article is C#.

I have written a number of articles on .NET programming recently, and a common feedback that I have received is that .NET is overly complicated to develop in. That it is much easier to code with language X and Notepad. On the face of it, this might seem like a valid criticism given Visual Studio's size and complexity, but it is not the language or even the framework that is to blame. Microsoft's C#.NET and Sun's Java are remarkably similar in their semantics and high level design - generally what the developer is acquainted with, as opposed to the language purists, who can tell you the difference between the CLR and JVM. The pain (and pleasure) of the development process that is most difficult and different with .NET, is the IDE, Visual Studio. Powerful? Definitely, but the ramp is steep and even simple things drag along a considerable amount of unnecessary cruft when the IDE is used.

I decided to strike back against the complex and visually breathtaking IDE based development using only "primitive" tools - a command-line and text editor. Kernighan and Ritchie's ubiquitous "The C Programming Language" is considered by many to be the most influential programming book of our time. Written in 1978, it immortalized the now well known phrase - "hello, world". The book states that "hello, world" is the basic hurdle to learning all languages:

"to leap over it you have to be able to create the program text somewhere, compile it successfully, load it, run it, and find out where your output went. With these mechanical details mastered, everything else is comparatively easy."

You need to have some perspective to truly appreciate this statement or you might be tempted to consider it overreaching. Dennis Ritchie designed the C programming language, and it was the C language that made portability possible for the Unix operating system. Unix and Linux, Minix, BSD, OSX, YouNameItOS and even Windows owe a great debt of gratitude to the language. Even the language C# is a derivative of Ritchie's C. So when in his book, it says that "hello, world" is important, we should listen.

So it is that I have taken my inspiration from K&R's work. I can think of no better method to expose the foundations of the development environment even in the year 2004 than the old, "hello, world" approach.

This article is divided into five "hello, world" tutorials covering command-line development using .NET:

  • HelloConsole: a console application that prints "hello, world" to the console.
  • HelloFile: a console application that prints "hello, world" to a file called Hello.txt.
  • HelloBrowser: a web application that displays "hello, world" to a web browser.
  • HelloWebService: a web service that will return "hello, world" in XML to a client.
  • HelloWebServiceClient: a web service client that will consume the web service.

Background

A basic understanding of .NET, the command-line, and working in Windows is assumed. Here are some good resources to help you get up to speed on these topics:

OK, I will admit that when I first sat down to write this section, I was intending to simply state the requirements and leave it to the reader as an exercise to actually do the getting and installation. However, when I sat down at my wife's computer and tested out the process, it quickly became apparent that more was required.

There are basically four required pieces to doing .NET development using the command-line:

  1. Windows 2000 or XP (Other versions may work, but I have not tested any other platforms).
  2. IIS - Internet Information Server

    To install IIS on your PC:

    • Click Start=>Settings=>Control Panel
    • Double click on 'Add or Remove Programs'.
    • Click on 'Add/Remove Windows Components'.
    • Check the box for Internet Information Services (IIS), if it is not already checked, and in Windows 2000, you may as well check the box for Script Debugger.
    • Click Next.

    After you install a major component like IIS, it is a really good idea to run Windows Update.

  3. The .NET Framework 1.1 SDK

    More information is available here.

    If you have Visual Studio 2003 installed, you will not need to install the Framework separately. Instead of a regular command-line, you can use the Visual Studio .NET 2003 Command Prompt which is located in the Visual Studio .NET Tools start folder. Alternatively, you can open a regular command-line and run the vsvars32.bat batch file to set up the environment for you.

    If you need to install the Framework, you will need to check and see if the Redistributable (runtime) is installed on your machine:

    • Click Start=>Settings=>Control Panel
    • Double click on 'Add or Remove Programs'.
    • Scroll through the list and see if there is an entry for Microsoft .NET Framework 1.1

    If it is not installed, download and install the Redistributable:

    Install the Microsoft .NET Framework 1.1 Redistributable - dotnetfx.exe, 23698 KB, Published 3/30/2004, Version 1.1.

    Once the Redistributable is installed, download and install the .NET Framework SDK Version 1.1 - setup.exe, 108757 KB, Published 4/9/2003, Version 1.1.

    If either of the links above do not work, both programs can be found at the Microsoft Download Center.

    Add SDK directory to the path:

    • Right click on 'My Computer' on the Desktop.
    • Select Properties.
    • Click the Advanced tab.
    • Click the 'Environment Variables' button.
    • In the System Variables panel, scroll down until you see the variable PATH.
    • Select PATH and click the Edit button.
    • Add the PATH to the SDK to the existing string in the Variable value Text Edit box (the SDK PATH will look something like D:\Program Files\Microsoft.NET\SDK\v1.1\Bin).
    • Click OK to close the Edit System Variable dialog and Save your changes.
    • Click OK to close the Environment Variables dialog.
    • Click OK to close the System Properties dialog.

    It is possible that .NET has lost its mind since the redistributable was installed. If you try to access a .aspx file from a web browser and do not see any data coming back, you may need to remind Windows about .NET. The fix is to re-register .NET by running the command:

    "%windir%\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe" -i

    To use the SDK, it is simplest to open a Command Prompt and use the SDK environment setup batch file:

    sdkvars.bat
  4. UltraEdit

    Well, OK, it is not a requirement, but it will sure make things easier. Get it here. If you do not have a decent text editor, Notepad will work OK.

You should now be set up to develop with the command-line. It is time to begin the tutorials.


HelloConsole

This tutorial is the easiest of the five. When you have finished it, you will have the pleasure of seeing the phrase "hello, world", printed on the command-line.

OK, let's get started. What are the goals? Borrowing directly from Kernighan and Ritchie, these will be our goals for all of the tutorials:

  • Create the program text
  • Compile the program
  • Load the program
  • Run the program
  • Locate the output

Create the program text

In order to create the program text, you will need to use a text editor of some sort. I prefer using UltraEdit, although Textpad or Notepad will work as well. Do not even bother with Word or Wordpad, these are arguably word processors and they tend to do funny things to text files. Fire up the editor and you will be ready to begin.

Here is K&R's "hello, world" C program in all its splendor, it is the model I am replicating, so I feel it is fitting to include it here:

C#
//reader Ryan Beesley noticed that the original quote 
//lacked an include needed to compile
//so I added the following include - it is not part of the 
//original K&R hello, world program
#include "stdio.h"

main()
{
  printf("hello, world\n");
}

The C#.NET code that is required to print "hello, world" to the console is similarly simple:

C#
1  using System;
2
3  namespace mynamespace {
4    public class HelloWorld {
5      public static void Main(string [] args) {
6        Console.WriteLine("hello, world");
7      }
8    }
9  }
  • Line 1 This is a using directive that tells the compiler that we will be referencing objects that are included in the System namespace. According to Microsoft, "The System namespace contains fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions". For our purposes, the System namespace provides the handy, dandy Console object that will allow us to print "hello, world" to the console.
  • Line 2 This is an empty line :) White-space, space, tab, carriage return, etc. in code (not strings) is generally considered insignificant, I tend to think of white-space as condensing to a single space or blank line.
  • Line 3 This is a namespace directive that tells the compiler to segregate our code in its own namespace semantically. This is not really required here, but it is good form. If you put any classes that you create in your own namespace, you will not be bitten by namespace collisions down the road. A namespace collision is what happens when there exists two semantic elements that have the same name. For instance, let's say that I create a class called Car, and somewhere else within the same project, someone else also creates a Car class. If I include both classes in my project, their names will collide unless they are in their own namespaces.
  • Line 4 This is the class declaration, our class is publicly accessible and is called HelloWorld.
  • Line 5 The Main method. Console applications are required to have a Main method. The Main method is the method that will be executed by the operating system when the program is loaded and run. Main is public and static, it does not return anything and it takes an array of strings as arguments. static basically means that the method can be called without instantiating a HelloWorld object. The arguments are include by convention, we will not be passing in any arguments.
  • Line 6 "hello, world" gets printed by this call to the Console object's WriteLine method which writes the argument to the console followed by a carriage return.
  • Line 7 End of the Main method.
  • Line 8 End of the HelloWorld class definition.
  • Line 9 End of the namespace.

Save the file to your hard drive as HelloConsole.cs and open a command prompt.

Compile the program

Compile the application using the C# compiler:

csc HelloConsole.cs

This should produce output similar to the following, without error.

Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

Compiling the application will generate an executable named HelloConsole.exe.

Load and run the program

Loading and running the program are accomplished in a single step. Load and run the application from the command-line by typing:

HelloConsole.exe

Locate the Output

Console output is incredibly easy to find. Generally, it appears on the line immediately following the command itself. Running the program should produce the following output:

hello, world

Congratulations, you have completed the HelloConsole tutorial. Now, I know what some of you are thinking, "It took nine lines to produce the same output K&R did in four? Ha! Gotcha, I knew .NET was lame." Well, it is not that simple. Here is a minimalist C#.NET HelloWorld console example for the purist:

C#
1  class HelloWorld {
2    public static void Main(string [] args) {
3      System.Console.WriteLine("hello, world");
4    }
5  }

It is still bigger than the K&R version, but not by much.


HelloFile

HelloFile is going to be a near duplicate of HelloConsole with the addition of the ability to write to a file. When you have finished this tutorial, you will have a file named Hello.txt in the same directory as the program, that has the phrase, "hello, world" as the contents.

Create the program text

Here is the code for the application:

C#
1  using System;
2  using System.IO;
3
4  namespace mynamespace {
5    public class HelloWorld {
6      public static void Main(string [] args) {
7        FileInfo fi = new FileInfo("Hello.txt");
8        StreamWriter sw = fi.CreateText();
9        sw.WriteLine("hello, world");
10        sw.Close();
11      }
12    }
13  }
  • Line 2 A using declaration for the System.IO namespace. According to Microsoft, "The System.IO namespace contains types that allow reading and writing to files and data streams, and types that provide basic file and directory support." For our purposes, System.IO allows us to access the FileInfo and StreamWriter classes using the shorthand of their class names.
  • Line 7 Instantiate a FileInfo object that is attached to the file Hello.txt. We use a FileInfo object because it performs better than a File object. File objects contain static methods that need to check security every time you call one. FileInfo objects do not need to check security except when they are first used. FileInfo provides us with file related functions.
  • Line 8 Instantiate a StreamWriter using the FileInfo object's CreateText method. The StreamWriter will serve a similar purpose as the Console object did in the previous example, with the difference that output will be directed to the file instead of the console.
  • Line 9 Use the StreamWriter WriteLine() method to write "hello, world" to the file.
  • Line 10 Close the StreamWriter. This is important because we do not want the file to remain open after we write the string to it. If it was open and the program terminated abnormally, the file might get corrupted, closing prevents this possibility.

Save the file to your hard drive as HelloFile.cs and open a command prompt.

Compile the program

Compile the application using the C# compiler:

csc HelloFile.cs

Compiling the application will generate an executable named HelloFile.exe.

Load and run the program

HelloFile.exe

There will not be any discernable output on the console, remember that we are directing the output to the file Hello.txt.

Locate the Output

Where did the output go? We told the program to send its output to the file Hello.txt. The file should be located in the same directory that the HelloFile.exe file was run from. The easiest way to view the file's contents is to use the type command:

type Hello.txt

You should see the following output:

hello, world

That is all there is to HelloFile.


HelloBrowser

With this tutorial, we begin to move into the 21st century. At the end of the tutorial, you will have a browse-able web application that is running on a web server that, when called, will return HTML with the phrase, "hello, world", as the contents.

Create the program text

HelloBrowser is different than the console applications in that the program will run in the context of the local web server and its output will be sent to a browser as HTML.

I will be using code-behind. Code-behind is new to .NET programming, and for our purposes, refers to the fact that algorithms and program logic reside in a separate file from the HTML that comprises the graphical user elements. I will not belabor it, but code-behind is the only way to go, mixing HTML and code is a nightmare waiting to prey on the weak minded.

What this means is that there will be two files, one for HTML and one for C#.NET code.

Here is the HTML file, called HelloBrowser.aspx.

ASP.NET
1  <%@ Page language="c#" Codebehind="HelloBrowser.aspx.cs"
 AutoEventWireup="false" Inherits="mynamespace.HelloWorld" %>
2  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3  <HTML>
4    <body>
5      <form id="Form1" method="post" runat="server">
6        <DIV id="divHelloWorld" runat="server"></DIV>
7      </form>
8    </body>
9  </HTML>
  • Line 1 This is the Page directive and the attributes that we will concern ourselves with are:
    • language, C#, of course.
    • Codebehind, the name of the cs file.
    • Inherits, the namespace and class of the code-behind class.
  • Line 5 FORM tag that runs at server, we will programmatically modify the form in code prior to it being rendered to the client.
  • Line 6 A DIV tag to hold the "hello, world" string.

Save the file to disk as HelloBrowser.aspx.

Here is the C#.NET file, called HelloBrowser.aspx.cs.

C#
1  using System;
2  using System.Web.UI.HtmlControls;
3
4  namespace mynamespace
5  {
6    public class HelloWorld : System.Web.UI.Page
7    {
8      protected HtmlGenericControl divHelloWorld;
9
10     private void Page_Load(object sender, System.EventArgs e)
11     {
12       divHelloWorld.InnerText = "hello, world";
13     }
14
15     override protected void OnInit(EventArgs e)
16     {
17       this.Load += new System.EventHandler(this.Page_Load);
18     }
19   }
20 }
  • Line 2 A using directive for the System.Web.UI.HtmlControls namespace. If we did not include it, it would require that we type System.Web.UI.HtmlControls.HtmlGenericControl to instantiate the DIV tag in our code.
  • Line 6 HelloWorld class declaration that derives from the System.Web.UI.Page class that .NET provides. The Page class is pre wired with events related to web server operation. We are going to make use of this functionality when we tap into the Page_Load() event to set the text of the DIV tag.
  • Line 8 Instantiate a System.Web.UI.HtmlControls.HtmlGenericControl object for our DIV tag (declared in the HTML, line 6 previously).
  • Line 10 This is our event handler for the System.Web.UI.Page Page_Load() event. It is where we will set the text of the DIV tag.
  • Line 12 Set the InnerText property of the DIV tag to "hello, world".
  • Line 15 The OnInit method is overridden to give us a place to add our event handler to the HelloWorld Page_Load() event.
  • Line 17 Actually, add the EventHandler Page_Load() to HelloWorld.Load().

      Save the file to disk as HelloBrowser.aspx.cs.

      Compile the program

      This is where things get interesting. The .aspx file will be compiled at run time by the web server. The .aspx.cs file will need to be compiled into a .dll. First, though, let's prepare for the files. This is a web application after all - it needs a little more in the way of deployment than a simple console application.

      Create a directory to contain the .aspx file:

      md HelloBrowser

      Copy HelloBrowser.aspx to the HelloBrowser directory.

      copy HelloBrowser.aspx HelloBrowser

      Create a directory to contain the .aspx.cs assembly .dll file:

      md HelloBrowser\bin

      Compile the .aspx.cs file.

      Open a command prompt and type:

      csc /t:library /out:Hellobrowser\bin\HelloBrowser.dll HelloBrowser.aspx.cs

      You should see something like the following:

      Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
      for Microsoft (R) .NET Framework version 1.1.4322
      Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

      This should create a file HelloBrowser.dll in the HelloWorld\bin directory.

      Create a virtual directory in the web server.

      • Right click on the My Computer icon on the Desktop and select Manage.
      • Expand Services and Applications=>Internet Information Services=>Web Sites
      • Right click on the Default Web Site and select New=>Virtual Directory...
      • Click Next.
      • Enter HelloB as the alias.
      • Browse to the HelloBrowser directory and click OK.
      • Click Next.
      • Click Next again (Read and Run scripts will be pre-selected).
      • Click Finish.

      Load and run the program

      These steps will be managed by the web server when the page is requested. To test, type the address below into your browser's address bar:

      http://localhost/HelloB/HelloBrowser.aspx

      Locate the Output

      The output will be in the browser's display area. I have chosen to use the Mozilla Browser 1.6 available here as the browser for this article. Mozilla is a much more advanced browser than Microsoft's Internet Explorer and it can be a developer's best friend. However, this is one big caveat - some sites on the web are not Mozilla friendly and you will definitely need to keep IE around. It is also a good idea to use IE to develop UI elements for web pages - it is the most popular browser. Feel free to use IE for the tutorials - I tested with IE and Mozilla. Here is the output:

      HelloBrowser

      That is it for HelloBrowser.


      HelloWebService

      This is the most difficult of the tutorials, but when you are finished, you will be pleased to find that you have created an XML web service that exposes a HelloWorld method to any client that has access to the web server. The method will return a SOAP document containing XML with the phrase "hello, world" as the content, to any client requesting it.

      Create the program text

      The web service will be written using code-behind and will operate in the context of the web server. There will be two files, one for the WebService directive and one for C#.NET code.

      Here is the WebService directive, called HelloWebService.asmx.

      ASP.NET
      1  <%@ WebService Language="c#" Codebehind="HelloWebService.asmx.cs"
       Class="mynamespace.HelloWebService" %>
      • Line 1 The attributes are as follows:
        • language, C#, of course.
        • Codebehind, the name of the cs file.
        • Class, the namespace and class name of the code-behind class.

      Save the file to disk as HelloWebService.asmx.

      Here is the C# file, HelloWebService.asmx.cs, that defines the web service logic:

      C#
      1  using System;
      2  using System.Web.Services;
      3
      4  namespace mynamespace
      5  {
      6    [WebService(Namespace="http://sentech.com")]
      7    public class HelloWebService : WebService
      8    {
      9      [WebMethod]
      10      public string SayHelloWorld()
      11      {
      12        return "hello, world";
      13      }
      14    }
      15  }
      • Line 2 A using directive for the System.Web.Services namespace.
      • Line 6 A WebService attribute. If you do not provide this, you will get a page of warnings about the tempuri namespace.
      • Line 7 The HelloWebService class derives from WebService and is what makes this a web service. Per Microsoft, "Defines the optional base class for XML web services, which provides direct access to common ASP.NET objects, such as application and session state."
      • Line 9 A WebMethod attribute that tells the compiler to set the following method as a web method.
      • Line 10 The meat of our class that does the work of returning "hello, world" to a web service client.
      • Line 12 The actual string "hello, world" is returned.

      Save the file to disk as HelloWebService.asmx.cs.

      Compile the program

      The .asmx file will be compiled at run time by the web server. The .asmx.cs file will need to be compiled into a .dll. First, though, let's prepare for the files. This is a web service - it needs more in the way of deployment.

      Create a directory to contain the .asmx file:

      md HelloWebService

      Copy the HelloWebService.asmx file to the HelloWebService directory:

      copy HelloWebService.asmx HelloWebService

      Create a directory to contain the .asmx.cs file:

      md HelloWebService\bin

      Compile the .asmx.cs file.

      Open a command prompt and type:

      csc /t:library /out:HelloWebService\bin\HelloWebService.dll 
                   HelloWebService.asmx.cs

      You should see something like the following:

      Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
      for Microsoft (R) .NET Framework version 1.1.4322
      Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

      This should create a file HelloWebService.dll in the HelloWebService\bin directory.

      Create a virtual directory in the web server.

      • Right click on the 'My Computer' icon on the Desktop and select Manage.
      • Expand Services and Applications=>Internet Information Services=>Web Sites
      • Right click on the Default Web Site and select New=>Virtual Directory...
      • Click Next.
      • Enter HelloWS as the alias
      • Browse to the HelloWebService directory and click OK.
      • Click Next.
      • Click Next again (Read and Run scripts will be pre-selected)
      • Click Finish.

      Load and run the program

      These steps will be managed by the web server when the page is requested. To test it out, type the address below into your browser's Address bar:

      http://localhost/HelloWS/HelloWebService.asmx

      Locate the Output

      In order to locate the output of a web service, you will need to perform a few steps. The browser page shows the web methods that are available to use.

      HelloWebService

      You can choose one of two paths here. One is the web method SayHelloWorld. The other is the webservice service description. First, look at the service description.

      Service Description

      Next, go back and select the SayHelloWorld web method.

      This brings you to a page that shows some sample SOAP code for those of you that want to delve deeper. There is also a button that says, Invoke, press the button.

      HelloWebService WebMethod

      This simulates a client of the web service requesting the SayHelloWorld web method via webservices.

      WebService Invoked

      There is one additional page that we might be interested in, and that is the .disco file, or Discovery document of the web service. To display the .disco file, browse to:

      http://localhost/HelloWS/HelloWebService.asmx?DISCO

      The Disco File

      That is it for HelloWebService.


      HelloWebServiceClient

      What good would a web service be without a client application? None, so here is that application. It is a simple web application that calls the web service created in the previous tutorial and displays the phrase, "hello, world", returned by the web service in the browser window.

      Create the program text

      This is another code-behind web application, but with a twist - we need to create a proxy. Web services use a pretty sophisticated communication mechanism. Thankfully, the .NET Framework provides the ability to auto-generate the proxy code and lets us concentrate on the productive stuff.

      First, some prep work - create a directory to contain the web service client web application:

      md HelloWebServiceClient

      We need a directory for the code-behind DLL:

      md HelloWebServiceClient\bin

      Create a virtual directory in the web server.

      • Right click on the 'My Computer' icon on the Desktop and select 'Manage'.
      • Expand Services and Applications=>Internet Information Services=>Web Sites
      • Right click on the Default Web Site and select New=>Virtual Directory...
      • Click Next.
      • Enter HelloWSC as the alias.
      • Browse to the HelloWebServiceClient directory and click OK.
      • Click Next.
      • Click Next again (Read and Run scripts will be pre-selected)
      • Click Finish

      To generate the proxy code, open a command prompt, and from the same directory as the .aspx.cs file:

      wsdl /out:HelloWebService_proxy.cs 
        http://localhost/HelloWS/HelloWebService.asmx?WSDL

      This should result in some semblance of the following output:

      Microsoft (R) web services Description Language Utility
      [Microsoft (R) .NET Framework, Version 1.1.4322.573]
      Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
      
        Writing file 'HelloWebService_proxy.cs'.

      Here is the code for the .aspx web application file:

      ASP.NET
      1  <%@ Page language="c#" Codebehind="HelloWebServiceClient.aspx.cs"
       AutoEventWireup="false" Inherits="mynamespace.HelloWorld" %>
      2  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
      3  <HTML>
      4    <body>
      5      <form id="Form1" method="post" runat="server">
      6        <DIV id="divHelloWorld" runat="server"></DIV>
      7      </form>
      8    </body>
      9  </HTML>
      • Line 1 The Codebehind and Inherits attributes reflect the code-behind class location and name.

      Save the file to disk as HelloWebServiceClient.aspx.

      Here is the C# code-behind source:

      C#
      1  using System;
      2  using System.Web.UI.HtmlControls;
      3
      4  namespace mynamespace
      5  {
      6    public class HelloWorld : System.Web.UI.Page
      7    {
      8      protected HtmlGenericControl divHelloWorld;
      9
      10      private void Page_Load(object sender, System.EventArgs e)
      11      {
      12        HelloWebService hello = new HelloWebService();
      13        divHelloWorld.InnerText = hello.SayHelloWorld();
      14      }
      15
      16      override protected void OnInit(EventArgs e)
      17      {
      18        this.Load += new System.EventHandler(this.Page_Load);
      19      }
      20    }
      21  }

      This file is remarkably similar to the web application's code-behind.

      • Line 12 Instantiate a HelloWorld web service class.
      • Line 13 Set the DIV tag to the value returned by calling the web service's SayHelloWorld() method.

      Save the file to disk as HelloWebServiceClient.aspx.cs.

      Compile the program

      Compile the proxy:

      csc /t:library /out:HelloWebServiceClient\bin\HelloWebService_proxy.dll 
                 HelloWebService_proxy.cs

      The output should resemble:

      Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
      for Microsoft (R) .NET Framework version 1.1.4322
      Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

      Compile the code-behind:

      csc /t:library /r:HelloWebServiceClient\bin\HelloWebService_proxy.dll \
      /out:HelloWebServiceClient\bin\HelloWebServiceClient.dll HelloWebServiceClient.aspx.cs

      The output will resemble:

      Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
      for Microsoft (R) .NET Framework version 1.1.4322
      Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

      Copy the HelloWebServiceClient.aspx file to the HelloWebServiceClient directory:

      copy HelloWebServiceClient.aspx HelloWebServiceClient

      Load and run the program

      These steps will be managed by the web server when the page is requested. To test it out, type the address below into your browser's Address bar:

      http://localhost/HelloWSC/HelloWebServiceClient.aspx

      Locate the Output

      The output will be in the browser window and will appear as it did in the HelloBrowser application.

      HelloWebServiceClient

      Conclusion

      If you have come this far, you are serious about your command-line .NET experience. My hope is that you have found this article interesting and useful.

      Please let me know what you think.

      Email the author: Will Senn.

      References

      • Kernighan, B.,& Ritchie, D. (1978). The C Programming Language (pp. 5-6). New Jersey, Prentice-Hall.

      Resources

      Background Resources

      General Resources

      History

      Version 1.0 - This is the first version of this article.

    • License

      This article, along with any associated source code and files, is licensed under The BSD License


      Written By
      Instructor / Trainer Tarleton State University
      United States United States
      Will Currently serves as Assistant Professor of Computer Information Systems. Previously he led research, development and product delivery efforts on a global scale. He has a long career as a software architect and developer and enjoys programming in any language on any platform for any good purpose.

      Comments and Discussions

       
      GeneralMy vote of 5 Pin
      PIEBALDconsult30-Jul-10 7:11
      mvePIEBALDconsult30-Jul-10 7:11 
      QuestionNeed help: I got errors Pin
      daoc31-Aug-08 20:32
      daoc31-Aug-08 20:32 
      AnswerRe: Need help: I got errors Pin
      Will Senn1-Sep-08 3:14
      professionalWill Senn1-Sep-08 3:14 
      GeneralRe: Need help: I got errors Pin
      daoc2-Sep-08 18:36
      daoc2-Sep-08 18:36 
      AnswerRe: Need help: I got errors: different error with IIS5.1 Pin
      daoc6-Sep-08 2:24
      daoc6-Sep-08 2:24 
      GeneralRe: Need help: I got errors: different error with IIS5.1 Pin
      Will Senn6-Sep-08 4:51
      professionalWill Senn6-Sep-08 4:51 
      AnswerRe: Need help: I got errors Pin
      Amit Joneja15-Jul-10 9:56
      Amit Joneja15-Jul-10 9:56 
      Generalit is good Pin
      jianbinlei19-Aug-08 5:44
      jianbinlei19-Aug-08 5:44 
      GeneralFreaking Cool Pin
      Jonathan C Dickinson21-Jul-08 1:59
      Jonathan C Dickinson21-Jul-08 1:59 
      Generalit is helpfull. thanks Pin
      hiepdinh14-Nov-07 19:48
      hiepdinh14-Nov-07 19:48 
      Generalit is so useful Pin
      Ozgur KOC22-Jan-07 9:37
      Ozgur KOC22-Jan-07 9:37 
      GeneralHelp... Pin
      Anonymous10-Jun-05 10:46
      Anonymous10-Jun-05 10:46 
      GeneralRe: Help... Pin
      Will Senn10-Jun-05 12:19
      professionalWill Senn10-Jun-05 12:19 
      Generalnow ... Pin
      Jean-Michel Reghem2-Jun-04 3:02
      Jean-Michel Reghem2-Jun-04 3:02 
      GeneralRe: now ... Pin
      Will Senn2-Jun-04 3:10
      professionalWill Senn2-Jun-04 3:10 
      GeneralVery nice Pin
      Ryan Beesley5-May-04 11:24
      Ryan Beesley5-May-04 11:24 
      I have to agree with the other comment, I like how you used the line numbers and explained everything -- including the spaces.

      It's nice to see an article like this that reminds people that C# is not synonymous with Visual Studio. The article flowed nicely and your logical pregression made each piece easy to digest.

      /Ryan
      GeneralRe: Very nice Pin
      Will Senn5-May-04 12:21
      professionalWill Senn5-May-04 12:21 
      GeneralRe: Very nice Pin
      Polis Pilavas25-May-04 4:35
      Polis Pilavas25-May-04 4:35 
      GeneralOpps, K&amp;R won't compile... Pin
      Ryan Beesley5-May-04 11:00
      Ryan Beesley5-May-04 11:00 
      GeneralRe: Opps, K&amp;R won't compile... Pin
      Will Senn5-May-04 11:26
      professionalWill Senn5-May-04 11:26 
      GeneralRe: Opps, K&amp;R won't compile... Pin
      Will Senn5-May-04 12:22
      professionalWill Senn5-May-04 12:22 
      GeneralRe: Opps, K&amp;R won't compile... Pin
      Kjell Holmgren10-May-04 7:42
      professionalKjell Holmgren10-May-04 7:42 
      GeneralRe: Opps, K&amp;R won't compile... Pin
      Will Senn12-May-04 6:12
      professionalWill Senn12-May-04 6:12 
      GeneralRe: Opps, K&amp;R won't compile... Pin
      Kjell Holmgren12-May-04 6:56
      professionalKjell Holmgren12-May-04 6:56 
      GeneralRe: Opps, K&amp;R won't compile... Pin
      Ryan Beesley13-May-04 0:16
      Ryan Beesley13-May-04 0:16 

      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.