How to: Create a Console Application Client
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

How to: Create a Console Application Client 

Code Example

Creating a console application that acts as a Web service client is fairly simple. Once a proxy class is created, a new instance of the proxy class can be created as long as it is accessible by the console application. The easiest way to make it accessible is to compile the proxy class into the assembly for the console application. Alternatively, the proxy class can be compiled into an assembly and deployed where the console application can access it.

To create a Web service console client application

  1. Create a proxy for the Web service.

    Wsdl http://www.contoso.com/Counter.asmx?WSDL
    
    

    Wsdl /language:VB http://www.contoso.com/Counter.asmx?WSDL
    

    For more information, see Creating an XML Web Service Proxy.

  2. Create a console application.

  3. Create an instance of the proxy class in your client code.

    Counter myCounter = new Counter();
    
    

    Dim myCounter As New Counter()
    
  4. Call the method of the proxy class that communicates with your Web service method.

    UsageCount = counter.ServiceUsage();
    
    

    UsageCount = counter.ServiceUsage()
    
  5. Compile the console application into an executable. In the following example, the console application was saved as UsageMonitor.

    csc /t:exe /r:System.Web.dll,System.XML.dll,System.Web.Services.dll UsageMonitor.cs Counter.cs
    
    

    vbc /t:exe /r:System.dll,System.Web.dll,System.XML.dll,System.Web.Services.dll UsageMonitor.vb Counter.vb
    

Example

 using System;
class UsageMonitor {
   public static void Main(string[] args) {
     int UsageCount;
     // Create an instance of the Web service class.
     Counter myCounter = new Counter();
     // Call the Web service method ServiceUsage.
     UsageCount = myCounter.ServiceUsage();
     // Output the results to the console.
     if (UsageCount == 1)
       Console.WriteLine("Web service has been utilized >" + UsageCount.ToString() + "< time.");
     else      
       Console.WriteLine("Web service has been utilized >" + UsageCount.ToString() + "< times.");
  }  
}

See Also

Show:
© 2016 Microsoft