Home arrow ASP.NET arrow Page 4 - Understanding .NET Remoting
ASP.NET

Understanding .NET Remoting


In this article, Aravind shows you how to build scalable, reliable and high-performance web services using the .NET remoting infrastructure.

Author Info:
By: Wrox Team
Rating: 4 stars4 stars4 stars4 stars4 stars / 108
November 25, 2002
TABLE OF CONTENTS:
  1. · Understanding .NET Remoting
  2. · Getting Started
  3. · Hosting the Remote Object on IIS
  4. · Method 1 (contd.)
  5. · Hosting the Remote Object in a Managed .NET Application Executable
  6. · Transport Channels
  7. · Serialization Formatters
  8. · Conclusion

print this article
SEARCH DEVARTICLES

Understanding .NET Remoting - Method 1 (contd.)
(Page 4 of 8 )

This is the listing for the ASP.NET page that consumes the Diner Web Service using the code-behind assembly that we just saw in the previous section:

<%@ Page language="C#" Codebehind="PizzaRemotingClientHTTP" & _
inherits="PizzaRemotingClientHTTP.RemoteClient" %>

.........

<asp:DataList runat="server" id="PizzaList"
RepeatColumns="2" RepeatDirection="Vertical" RepeatMode="Table" DataSource='<%# PizzaMenu %>'
Width="100%">
<property name="AlternatingItemStyle">
<asp:TableItemStyle BackColor="#f5deb3"/>
</property>
<template name="ItemTemplate">
<asp:Panel runat=server font-size="12pt" font-bold="true">
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</asp:Panel>
<asp:Label runat=server font-Size="8pt"
Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>'>
</asp:Label>
<asp:Label runat=server font-Size="10pt" Text="$" ForeColor="Blue">
</asp:Label>
<asp:Label runat=server font-Size="10pt" ForeColor="Blue"
Text='<%# DataBinder.Eval(Container.DataItem, "Cost") %>' >
</asp:Label>
</template>
</asp:DataList>


Method 2: (Using a configuration file on the client to register the channel and specify the object's URN)
Creating and registering the channel explicitly and then using Acivator.GetObject is just one way of invoking the remote object. You can also specify the channel and the URI endpoint of the remote object through a configuration file , and just instantiate the Diner object using new . The client application will use the information in the loaded configuration file to register the channel and activate the object at the URI endpoint specified.

The general format of the client configuration file is as follows:

Name#Name of the Application
Assembly#[AssemblyName]#[RemoteApplicationName]
                      
#[FullTypeName]=[ObjectURI]
RemoteApplication#[RemoteApplicationName]
                       #[RemoteApplicationURI]
Channel#[ChannelAssemblyName]#[ChannelFullTypeName]#[Name=Value;Name=Value]


So based on the above format, here's how your configuration file ( MyDinerClient.cfg ) would look like:

Name#MyDinerClientConfig
Assembly#MyDiner#MyDiner#MyDiner.Diner=
                        HTTP://bingo:80/MyDiner/Diner.soap
RemoteApplication#MyDiner#HTTP://bingo:80/MyDiner
Channel#System.Runtime.Remoting
               #System.Runtime.Remoting.Channels.TCP.TCPChannel
Channel#System.Runtime.Remoting
              #System.Runtime.Remoting.Channels.HTTP.HTTPChannel


To load this configuration file, we have to use the RemotingServices.ConfigureRemoting method and pass it the name of the client configuration file to use. The information in the configuration file is used to register the channel and use the specified remote URI endpoint to activate the object. You must load the configuration file only once, typically when your application starts up. Shown below is the global.asax file for an ASP.NET consumer application that loads the configuration file.

<%@ Import Namespace="System.Runtime.Remoting" %>
<script runat="server" language="vb">
Sub Application_OnStart()
RemotingServices.ConfigureRemoting(HttpContext.Current.
Server.MapPath("MyDinerClient.cfg"))
End Sub
</script>


So now, since we have all the details specified in the configuration file, we do not have to explicitly register the channel or provide details about the object's URN endpoint in our code. You would simply have to create the object using new and then call its methods as shown below:

// Create an instance of the remote object
Diner dinerObj = new Diner();

// Get Today's Menu from the remote Pizza Service
if(dinerObj != null)
m_listPizza = dinerObj.getPizzaMenu();


If there's an inkling of doubt whether your ASP.NET page is accessing the locally deployed assembly instead of the remote one, simply shut down the remote server or rename the assembly on the remote server and you will see that the client will choke.
blog comments powered by Disqus
ASP.NET ARTICLES

- How Caching Means More Ca-ching, Part 2
- How Caching Means More Ca-ching, Part 1
- Reading a Delimited File Using ASP.Net and V...
- What is .Net and Where is ASP.NET?
- An Object Driven Interface with .Net
- Create Your Own Guestbook In ASP.NET
- HTTP File Download Without User Interaction ...
- Dynamically Using Methods in ASP.NET
- Changing the Page Size Interactively in a Da...
- XML Serialization in ASP.NET
- Using Objects in ASP.NET: Part 1/2
- IE Web Controls in VB.NET
- Class Frameworks in VB .NET
- Cryptographic Objects in C#: Part 1
- Sample Chapter: Pure ASP.Net

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials