Deploying a .NET Remoting Object

You have seen how to deploy a Windows service and a serviced component (a COM+ application written in .NET). The principles you learned also apply to deploying a .NET Remoting object because it is usually implemented as a Windows service or a serviced component. There are a few other options for deploying .NET Remoting objects.

You can deploy them as stand-alone executables, which must be started manually. This requires copying the executable and the application configuration file to the server and manually executing the file. You can improve upon this by using a scheduler or file watcher to make sure the application is executing, but it is not going to be as robust as a Windows service or COM+ application.

The other option you have for deploying your .NET Remoting object is using IIS as a host for it. This enables you to take advantage of the authentication and encryption services built into IIS. This also cuts down on the amount of code you need to develop to provide these services.

start sidebar
Real World Scenario—Hosting .NET Remoting Objects in IIS

You are developing an application that keeps track of patient information for a hospital. The requirements state that you need to make sure the application is secure and performs well. You have decided to implement an object called PatientInfo that can be used to read and write various patient data. This object could have a need to be called in process, in another application domain or most likely on another server. You have no need for interoperability with this application, but need to make sure it is secure and performs well. In addition, you have a very tight deadline for delivery of this component of the application.

You decide to implement the object by using .NET Remoting and to use an HTTP for the protocol. This will enable you to host the application under Internet Information Server, which means you can save development time by taking advantage of the authentication (Basic or Windows Integrated) and encryption (SSL) services that are built into IIS. You also decide to use the binary formatter to serialize the object data that is moved between server and client. This performs much better than the SOAP formatter and can be used when interoperability is not an issue.

end sidebar

Hosting a .NET Remoting object in IIS is straightforward. You create a virtual directory on the server, add a web.config file with the necessary configuration information for remoting, and then deploy the compiled assembly containing the remoting type to the \bin directory in the virtual directory you created for a private application or register it in the GAC to make it shared among all applications. There are, however, a few points to consider:

  • You cannot specify the application name of the Remoting object when deploying to IIS. The virtual directory name that you create is the name of the application.

  • You must use the HttpChannel, but you have your choice for Formatters, either Binary or Soap.

  • You cannot use the <debug> element in a web.config file, which is used to alert you of errors in your configuration file as soon as the assembly is loaded.

  • You cannot use the <client>element in the web.config file to configure your client web application automatically. This can be done by using the RemotingConfiguration class in the global.asax files’s Application_Start event.

  • You can configure the HttpChannel in the web.config, but you do not specify a port because this is done in IIS.

In Exercise 10.8, you will deploy a .NET Remoting object to a virtual directory in IIS and connect to it with a client.

Exercise 10.8: Deploying a .NET Remoting Object in Internet Information Server

start example
  1. Create a new Visual Basic Project Class Library project called HWRemote.

  2. Add a reference to your project for System.Runtime.Remoting.dll.

  3. Replace the code in the class with following code to create the .NET Remoting server object:

    Imports System.Runtime.Remoting Public Class HWServer      Inherits MarshalByRefObject Public Function Message() As String    Return "Hello World!" End Function End Class
  4. Build the project.

  5. Add a new Visual Basic .NET Windows Application project to the solution by right-clicking on the solution and choosing Add Ø New Project.

  6. Name the project HWClient.

  7. Add a reference to the HWRemote project by right-clicking References in the Solution Explorer and choosing Add References. Click the Project tab on the Add References dialog box and select HWRemote project; then click the Select button and click OK.

  8. Add a Button control and a TextBox control to the form.

  9. Add the following Imports to the top of the source file:

    Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting.Channels.Http Imports HWRemote 
  10. Double-click the Button control and add the following to the Button1_Click event:

    ChannelServices.RegisterChannel(new HttpChannel()) Object obj = Activator.GetObject(typeof(HWServer), _ "http://localhost/RemoteHello/HWServer.rem") HWServer hws = CType(obj, HWServer) TextBox1.Text = hws.Message()
  11. Build the project to make sure it is correct.

  12. Create a new directory on the C: drive called RemoteHello. Create a directory in the RemoteHello directory called bin.

  13. Right-click the RemoteHello directory and choose Properties from the pop-up menu.

  14. Click the Web Sharing tab of the RemoteHello Properties dialog box.

  15. Select the option Share The Folder. The Edit Alias dialog box appears.

  16. Click the OK button to accept the defaults.

  17. Click the OK button of the RemoteHello Properties dialog box.

  18. Open the Internet Services Manager console by navigating to the Administrative Tools folder of Control Panel.

  19. Expand Your Computer Name, then expand the Default Web Site node.

  20. Right-click the RemoteHello virtual directory and choose Properties from the pop-up menu.

  21. Click the Configuration button on the Virtual Directory tab of the RemoteHello Properties dialog box.

  22. Click the OK button.

  23. Close the Internet Services Manager console.

  24. Navigate to the C:\RemoteHello folder. Right-click in the folder and create a new text document called web.config.

  25. Add the following to the text document:

    <system.runtime.remoting> <application> <service> <wellknown mode="SingleCall"     type="HWRemote.HWServer, HWRemote"     objectUri="HWServer.rem" /> </service> <channels> <channel ref="http" /> </channels> </application> </system.runtime.remoting> 
  26. Copy the assembly, HWServer.dll, from the My Documents\Visual Studio Projects\Exercise10_8\bin directory to the \bin directory of the C:\RemoteHello folder.

  27. Set the HWClient project as the startup project.

  28. Run the client to test the application. You should see “Hello World!” printed in the text box.

end example



MCAD/MCSD(c) Visual Basic. NET XML Web Services and Server Components Study Guide
MCAD/MCSD: Visual Basic .NET XML Web Services and Server Components Study Guide
ISBN: 0782141935
EAN: 2147483647
Year: 2005
Pages: 153

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