Hosting Your Server in IIS

Team-Fly    

 
.NET and COM Interoperability Handbook, The
By Alan Gordon
Table of Contents
Chapter Eleven.  .NET Remoting

Hosting Your Server in IIS

Creating your own server executable is an interesting exercise, but the reality is that, unless you have the time to build the proper thread-pooling and security support, you will be much better off hosting your .NET remoting server in IIS. Fortunately, it is easy to do this. To host the .NET remoting server in IIS, you have to perform the following steps:

  1. Create a virtual directory.

  2. Create a bin directory beneath the virtual directory and copy the server assembly and shared assembly to the bin directory.

  3. Edit the server configuration file.

  4. Edit the client configuration file.

Create a Virtual Directory

I won't go in depth into the steps to create a virtual directory because I have done this many times already in this book. Call your virtual directory MyCompany and make sure anonymous access is allowed. The requirement for anonymous access is motivated by a need for simplicity in my example, not an inherent need of .NET remoting.

Add a Bin Directory

You need to add a bin directory directly beneath your virtual directory to hold the implementation assembly for your .NET remoting server and the shared library assembly. The ASP.NET runtime looks for assemblies there. Copy the SharedLibrary assembly to the bin directory and also copy the assembly that contains the Company marshal-by-reference class to the bin directory.

Edit the Server Configuration File

You will need to make a number of edits to the server configuration file in order to make it work with IIS. First, you need to change the name of the configuration file to web.config , which is the name of the configuration file that the ASP.NET runtime looks for. Next, you need to remove all port numbers from the configuration file because specifying port numbers in the configuration file will interfere with IIS' connection handling. Finally, you need to make sure that you use a .soap or .rem extension for the object URI. To understand the reason for this, refer back to Chapter 10 where I talked about XML Web services and the ASP.NET runtime infrastructure. Remember I said that ASP.NET maps file extensions to HTTP handlers, which know how to process the contents of files with that extension. If you examine the default machine.config file at [WINNT]\Microsoft.NET\Framework\v1.0.3705\CONFIG\ , you see the following entries in the HttpHandlers tag:

 <httpHandlers>   ...  <add verb="*" path="*.rem"  type="  System.Runtime.Remoting.Channels.Http.Http   RemotingHandlerFactory  ,     System.Runtime.Remoting, Version=1.0.3300.0,     Culture=neutral,     PublicKeyToken=b77a5c561934e089" validate="false"/>  <add verb="*" path="*.soap"  type="  System.Runtime.Remoting.Channels.Http.HttpRemoting   HandlerFactory  ,   System.Runtime.Remoting, Version=1.0.3300.0,   Culture=neutral,   PublicKeyToken=b77a5c561934e089" validate="false"/> ... </httpHandlers> 

These entries indicate that files with an extension of .soap or .rem are mapped to a handler called System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, which knows how to process IIS-hosted .NET remoting servers. I have actually been using the .soap extension all along, but it was not a requirement that you use this extension when you build your own host process. It is a requirement that you use the .soap or .rem extension if you use IIS. The new configuration file for the server is the following:

 <configuration>   <system.runtime.remoting>     <application>       <service>         <wellknown mode="Singleton"         type="SharedLibrary.Company, SharedLibrary"         objectUri="Company.soap" />       </service>     </application>   </system.runtime.remoting> </configuration> 

Edit the Client Configuration File

In the client configuration file, you only need to make sure that the URL references the new virtual directory and that you remove any port numbers. The configuration file to access the IIS-hosted server looks as follows :

 <configuration>   <system.runtime.remoting>     <application>       <client>         <wellknown         type="SharedLibrary.Company,SharedLibrary"         url="http://localhost/MyCompany/Company.soap" />       </client>     </application>   </system.runtime.remoting> </configuration> 

Try running the client again, and you will notice that it works exactly as it did before. However, it will be more scalable now because it runs in IIS.


Team-Fly    
Top
 


. Net and COM Interoperability Handbook
The .NET and COM Interoperability Handbook (Integrated .Net)
ISBN: 013046130X
EAN: 2147483647
Year: 2002
Pages: 119
Authors: Alan Gordon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net