Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 312107 - Last Review: April 17, 2003 - Revision: 4.0
HOW TO: Host a Remote Object in Microsoft Internet Information Services
This article was previously published under Q312107
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
- Using Visual Studio .NET, create a new Visual C# .NET
Project by using the Class Library template. Name the project
HelloWorldObject.
- Rename the Class1.cs file that is created by default to
Hello.cs.
- 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";
}
}
}
- Right-click References in the Solution Explorer, and then select Add Reference. Add a reference to System.Runtime.Remoting.
- Build the solution.
Host the Remote Object in Microsoft Internet Information Services
- Create a new directory called
HelloWorldWeb (preferably under
\Inetpub\wwwroot\).
- Create a directory named bin beneath
the HelloWorldWeb directory.
- Copy the HelloWorldObject.dll file from the
HelloWorldObject\bin\debug\ directory to the HelloWorldWeb\bin\
directory.
- Use Notepad.exe to create a new file called
Web.config. Copy the following text, and then save it in
the HelloWorldWeb directory:
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall" type="HelloWorldObject.Hello, HelloWorldObject" objectUri="SimpleHelloWorld.soap" />
</service>
</application>
</system.runtime.remoting>
</configuration>
- Click Start, point to Programs, and then click Administrative Tools. Open Internet Services Manager.
- Create a virtual directory in IIS.
- 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
- Add a new Visual C# .NET project to the existing solution
by selecting the Console Application template. Name the project
Client.
- Rename the existing Class1.cs file to
TestClient.cs.
- 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"));
}
}
}
- Add references to the following:
- System.Runtime.Remoting
- HelloWorldObject.dll (by browsing to the location of
the .dll file)
- Build the client application.
- Verify that the IIS server is started, and then run
Client.exe, which is located in the debug\bin directory.
Microsoft
.NET Remoting: A Technical Overview
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/hawkremoting.asp)
APPLIES TO
- Microsoft .NET Framework Class Libraries 1.0
| kbfix kbhowtomaster KB312107 |
Retired KB Content DisclaimerThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate