Host a Remote Object in IIS

This article provides step-by-step instructions to host a remote object in Microsoft Internet Information Services. The article also provides instructions for how to build a simple client to call the remote object.

ITPro Today

November 7, 2005

2 Min Read
ITPro Today logo in a gray background | ITPro Today

Note The following .NET Framework Class Library namespaces are referenced in this article:
  System.Runtime.Remoting

This article provides step-by-step instructions to host a remote object in Microsoft Internet Information Services. The article also provides instructions for how to build a simple client to call the remote object.

Prerequisites:
  Microsoft Visual Studio .NET with Microsoft .NET Framework
  Microsoft Internet Information Services (IIS)

Build a Simple Remote Object

  1. Using Visual Studio .NET, create a new Visual C# .NET Project by using the Class Library template. Name the project HelloWorldObject.

  2. Rename the Class1.cs file that is created by default to Hello.cs.

  3. Replace the entire code for Hello.cs with the following:

using System;using System.Runtime.Remoting;namespace HelloWorldObject{public class Hello : MarshalByRefObject{public string HelloWorld(string str){return "Hello World received " + str + " from the client";}}}
  1. Right-click References in the Solution Explorer, and then select Add Reference. Add a reference to System.Runtime.Remoting.

  2. Build the solution.

Host the Remote Object in Microsoft Internet Information Services

  1. Create a new directory called HelloWorldWeb (preferably under Inetpubwwwroot).

  2. Create a directory named bin beneath the HelloWorldWeb directory.

  3. Replace the entire code for Hello.cs with the following:

  4. Use Notepad.exe to create a new file called Web.config. Copy the following text, and then save it in the HelloWorldWeb directory:

                                
  1. Click Start, point to Programs, and then click Administrative Tools. Open Internet Services Manager.<

  2. Create a virtual directory in IIS.

  3. Make the virtual directory alias SimpleHello, and then set the source directory to the HelloWorldWeb directory.

Build a Simple Console Application to Test the Remote Object

  1. Add a new Visual C# .NET project to the existing solution by selecting the Console Application template. Name the project Client.

  2. Rename the existing Class1.cs file to TestClient.cs.

  3. Replace the existing code in TestClient.cs with the following:

using System;using System.Runtime.Remoting;using System.Runtime.Remoting.Services;using System.Runtime.Remoting.Channels;using System.Runtime.Remoting.Channels.Http;using HelloWorldObject;namespace Client{class TestClient{[STAThread]static void Main(string[] args){HttpChannel http = new HttpChannel();ChannelServices.RegisterChannel(http);Hello obj = (Hello)Activator.GetObject(typeof(Hello),"http://localhost/SimpleHello/SimpleHelloWorld.soap");Console.WriteLine(obj.HelloWorld("CLIENT APPLICATION"));}}}
  1. Add references to the following:
    System.Runtime.Remoting
    HelloWorldObject.dll (by browsing to the location of the .dll file)

  2. Build the client application.

  3. Verify that the IIS server is started, and then run Client.exe, which is located in the debugbin directory.

http://support.microsoft.com/default.aspx?scid=312107

The above URL shows the page that this code was originally published on Microsoft.com

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like