This article has been excerpted from book "The Complete Visual C# Programmer's Guide" from the Authors of C# Corner.
It is also possible for Internet Information Server (IIS) to host remote objects. The Web-hosting example is in the Sample1 folder. The console client project is named WebClientExe.
To use IIS as a server, you must take a number of steps:
-
The remote object must be server activated.
-
Map a virtual directory, on the Web server, to the SimpleObjectLib folder.
-
The remote object can't be programmatically configured. It must use a web.config file in the virtual directory's root, see Listing 25.26.
Listing 25.26: Web.config
<?xml version="1.0" ?>
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="SingleCall"
type="SimpleObjectLib.SimpleObject, SimpleObjectLib"
objectUri="Simple.rem">
</wellknown>
</service>
<channels>
<channel
name="Server-Activated Web Client"
type="System.Runtime.Remoting.Channels.Http.HttpChannel, System.Runtime.Remoting"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
You should be aware of a number of items in the configuration file:
-
No port number need be specified, as IIS has already been configured to listen on a port, normally port 80.
-
The objectUri attribute in the wellknown element must use the extension .rem or .soap.
The client code remains the same as previous server-activated examples (see Listing 25.27). The client output is shown in Figure 25.16.
Listing 25.27: WebClient.cs
ChannelServices.RegisterChannel(new HttpChannel());
SimpleObject simple = null;
simple = (SimpleObject)Activator.GetObject( typeof(SimpleObject), "http://localhost/WebRemoting/Simple.rem");
string ret = null;
ret = simple.ConCatString( "using the", "Web for remoting.");
Figure 25.16: WebClientExe Output
Conclusion
Hope this article would have helped you in understanding Remoting over the Web. See other articles on the website on .NET and C#.
|
The Complete Visual C# Programmer's Guide covers most of the major components that make up C# and the .net environment. The book is geared toward the intermediate programmer, but contains enough material to satisfy the advanced developer. |