.Net Remoting Jim Fawcett CSE775 – Distributed Objects Spring 2004.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

COM vs. CORBA.
Web Service Ahmed Gamal Ahmed Nile University Bioinformatics Group
.NET Remoting in Delphi and C# Alain “Lino” Tadros President & CEO Falafel Software Inc. ComponentScience Inc. BORCON 2004.
.Net Remoting Pooja Panjala 06/17/10. Agenda What is.net Remoting? Explanation of terms Architecture Implementation of Remoting Sample example.net Security.
C# and Windows Programming Application Domains and Remoting.
.NET REMOTING CertSIG Tom Perkins. FUNDAMENTALS Distributed Applications Process A Process B Process C Objects can communicate across process boundaries.
Author: Bill Buchanan. Authentication (to identify the clients of your application) Authorization (to provide access controls for those clients) Secure.
Windows Communication Foundation and Web Services.
1 Advanced Programming Topics - II Objectives:  Background  Remoting  Types of remoting  Marshalling  Farmatters  Channels.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Distributed Systems Tutorial 2 -.NET Remoting. 2 What is Remoting?  Remoting allows you to pass objects or values across servers in different domains.
.NET Deployment Matt Smouse CSE775 – Distributed Objects Spring 2003.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Intro to dot Net Dr. John Abraham UTPA – Fall 09 CSCI 3327.
.NET, and Service Gateways Group members: Andre Tran, Priyanka Gangishetty, Irena Mao, Wileen Chiu.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Web Servers Web server software is a product that works with the operating system The server computer can run more than one software product such as .
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
JavaScript & jQuery the missing manual Chapter 11
Introduction to ASP.NET. Prehistory of ASP.NET Original Internet – text based WWW – static graphical content  HTML (client-side) Need for interactive.
.NET Remoting Architecture. Slide 2 CITE 4420.NET Remoting Topics Remoting Boundaries Crossing the Boundaries Distributed Applications Marshalling Channels.
.Net Remoting. 2 Distributed Computing under.Net In.Net, there are three levels of access to distributed computing machinery: In.Net, there are three.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
Distributed Communication via ASP.Net Web Services and.Net Remoting By Richard King.
Lecture 15 Introduction to Web Services Web Service Applications.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
.Net and Web Services Security CS795. Web Services A web application Does not have a user interface (as a traditional web application); instead, it exposes.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Introducing ASP.NET 2.0. Internet Technologies WWW Architecture Web Server Client Server Request Response Network HTTP TCP/IP PC/Mac/Unix + Browser (IE,
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
RMI remote method invocation. Traditional network programming The client program sends data to the server in some intermediary format and the server has.
.Net Remoting The Other RPC Architecture Doug Gregory October 27, 2003.
GUDURU PRAVEEN REDDY.NET IMPERSONATION. Contents Introduction Impersonation Enabled Impersonation Disabled Impersonation Class Libraries Impersonation.
The Module Road Map Assignment 1 Road Map We will look at… Internet / World Wide Web Aspects of their operation The role of clients and servers ASPX.
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
.NET Mobile Application Development XML Web Services.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
.NET Remoting. Remoting Introduction The process of programs or components interacting across certain boundaries either different processes or machines.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Windows Communication Foundation and Web Services
Jim Fawcett CSE681 – SW Modeling & Analysis Spring 2005
Jim Fawcett CSE775 – Distributed Objects Spring 2003
Review of Last Year’s Midterm
.NET Remoting Priyanka Bharatula.
Using Application Domains Effectively
Presentation 23 .NET Remoting Introduced
Advanced .NET Programming II 10th Lecture
Out-of-Process Components
Matt Smouse CSE775 – Distributed Objects Spring 2003
Microsoft .NET Remoting Essentials
Windows Communication Foundation and Web Services
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
Chapter 40 Remote Method Invocation
Chapter 46 Remote Method Invocation
Chapter 46 Remote Method Invocation
Out-of-Process Components
Matt Smouse CSE775 – Distributed Objects Spring 2003
Jim Fawcett Core Technologies Spring 2005
Jim Fawcett CSE791 – Distributed Objects Spring 2002
Message Passing Systems Version 2
Matt Smouse CSE775 – Distributed Objects Spring 2003
Message Passing Systems
Presentation transcript:

.Net Remoting Jim Fawcett CSE775 – Distributed Objects Spring 2004

.Net Remoting2 References  Programming Microsoft.Net, Jeff Prosise, Microsoft Press, 2002, Chap 15. –Excellent, clear discussion of basic remoting  Microsoft.Net Remoting, McLean, Naftel, Williams, Microsoft Press, 2003 –Best description of channel model I’ve seen  Advanced.Net Remoting, Ingo Rammer, Apress, 2002 –Well regarded book with fairly broad coverage of remoting   Programming.Net Web Services, Ferrara, MacDonald, O’Reilly, 2002

.Net Remoting3 Distributed Computing under.Net  In.Net, there are three levels of access to distributed computing machinery: –Low Level: System.Net.Sockets –Intermediate Level System.Runtime.InteropSerives – Access COM objects and Win32 API System.Runtime.Remoting – Access channels and CLR activation – Channels based on TCP or HTTP over TCP –High Level System.Web.Services System.Web.UI

.Net Remoting4 Distributed Computing under.Net  System.Net.Sockets –Provides low-level access to socket objects –You create listeners and send and receive just like we did in CSE691 – Software Modeling and Analysis  System.Runtime.Remoting –Provides access at a medium level of abstraction. –You create channels and proxies and do RPCs on remote objects –Data marshaling is much richer than under COM. You can send anything the CLR understands as long as it has a [serializable] attribute or derives from MarshalByRef. Basically you just add those.Net identifiers and the CLR takes care of everything else.

.Net Remoting5 Remoting.Net Libraries  System.Runtime.Remoting.Activation –Activate remote objects  System.Runtime.Remoting.Channels –Sets up channel sinks and sources for remote objects  System.Runtime.Remoting.Channels.HTTP –Uses SOAP protocol to communicate with remote objects  System.Runtime.Remoting.Channels.TCP –Uses binary transmission over sockets  System.Runtime.Remoting.Contexts –Set threading and security contexts for remoting  System.Runtime.Remoting.Messaging –Classes to handle message passing through message sinks  System.Runtime.Remoting.Metadata –Customize HTTP SoapAction type output and XML Namespace URL  System.Runtime.Remoting.Proxies  System.Runtime.Remoting.Services

.Net Remoting6 Distributed Computing under.Net  System.Web.Services –Servers are hosted under IIS –Use HTTP-GET and HTTP-POST or higher level SOAP  Simple Object Access Protocol (SOAP) –Wraps XML message in SOAP envelope (XML tags) –SOAP messages are interpreted by IIS and ASP –Typically use standard and/or custom COM components in ASP pages. –Active Server Pages (ASP) are XHTML pages with embedded server-side and client-side scripts that may access COM and C# objects for a significant part of their processing.

.Net Remoting7 Web Related.Net Libraries  System.Web –System.Web.Hosting Communicate with IIS and ISAPI run-time –System.Web.Mail –System.Web.Security cookies, web authentication, Passport –System.Web.Services – close ties to ASP.NET System.Web.Services.Description System.Web.Services.Discovery System.Web.Services.Protocol – raw HTTP and SOAP requests System.Web.SessionState – maintain state between page requests –System.Web.UI – access to WebForms

.Net Remoting8 Remote Procedure Call (RPC) Model  Remoting supports a client’s invocation of an object on a remote machine. –The server acts as a host for the remote object, loading it into memory and servicing client requests on a worker thread spawned by the server process’s main thread. All of this is transparent to the designer. –The client makes calls as if the object were instantiated on the local machine.

.Net Remoting9 Remoting Architecture .Net Remoting uses System.Runtime.Remoting  It is built on processing that supports: –Channels A channel is a socket-based communication mechanism that can use either basic TCP protocol or the higher HTTP layer. –Activation Activation is basically the same process that the CLR uses to create local objects. – You just have to tell the CLR what object you want. – The CLR manages its lifetime and marshals data and references back and forth, using a channel.

.Net Remoting10 Remoting Architecture

.Net Remoting11 Basic.Net Remoting – Remote Object  First create a remote-able object: –Design an object to be invoked remotely, derived from MarshalByRef –Implement the class as a C# library – this creates a dll. –Any objects that you need to pass to that object need to be serializable. The basic types like ints and strings already are serializable. Your class objects need to have the [Serializable] attribute and contain only serializable data members. Or they can derive from MarshalByRef.

.Net Remoting12 Remoting Architecture

.Net Remoting13 Basic.Net Remoting – the Server  Next Create a server: –Design a C# class, using a C# Console Application, or Empty Project in which you will create a WinForm. –In a member function – main will work: Create a TcpServerChannel Register the Channel with ChannelServices Register the type of object clients want to use remotely by calling RegisterWellKnownServiceType –Then, block the main thread. The object will be created by the CLR on its own thread and remote clients will access the object through the CLR. You don’t have to write any server code to support this access – the CLR takes care of it for you. –Create a reference to the remote-able object’s assembly, build, and run the server.

.Net Remoting14 Remoting Architecture

.Net Remoting15 Basic.Net Remoting – the Client  Create a client: –Design a C# class, using a C# Console Application, or Empty Project in which you will create a WinForm. –In a member function – main will work: Create a TcpServerChannel Register the Channel with ChannelServices –In a member function – main will work: Create a proxy to access the remote component. You do this by calling Activator.GetObject(…) and casting the result to the type of the remote object. – Note that both client and server need the assembly for the remote-able object. –Then, make calls on the remote object as needed. You simply use the proxy as if it were the real object. –Create a reference to the remote-able object’s assembly, build, and run the client.

.Net Remoting16 Remoting Architecture

.Net Remoting17 Server Notifications  The previous slides described a classic client/server configuration. –We often need something a little more sophisticated. In a classic client/server only the client initiates communication. For some applications you will have to have the “server” make notifications back on the “client”. –The next presentation discusses a callback reference mechanism that will work effectively for notifications by the server.

.Net Remoting18 Remoting Server Code static void Main(string[] args) { TcpServerChannel chan = new TcpServerChannel(8085); ChannelServices.RegisterChannel(chan); RemotingConfiguration.RegisterWellKnownServiceType( typeof(Hello), // type of the remote object "HelloObj", WellKnownObjectMode.Singleton ); System.Console.WriteLine("\n Hit to exit..."); System.Console.ReadLine(); } This server’s only role is to setup the channel, register the object, and wait while it is used by the client.

.Net Remoting19 Remotable Object Code public class Hello : MarshalByRefObject { private int count = 0; public Hello() { Console.WriteLine(" construction of Hello Object"); } public string say(string s) { ++count; Console.WriteLine(" " + s); string rtnMsg = “remote object received message #”; rtnMsg += count.ToString(); return (rtnMsg); } Just like any other class except that it derives from MarshalByRefObject

.Net Remoting20 Client Code class client { private Hello proxy; // void SetUpChannel() { TcpClientChannel chan = new TcpClientChannel(); ChannelServices.RegisterChannel(chan); } // void ActivateRemoteObject() { proxy = (Hello)Activator.GetObject( typeof(Hello), "tcp://localhost:8085/HelloObj" ); if(proxy == null) Console.WriteLine("can't activate object"); } Client sets up channel and constructs proxy. Then it uses object, as shown on next slide.

.Net Remoting21 static void Main(string[] args) { client clnt = new client(); clnt.SetUpChannel(); clnt.ActivateRemoteObject(); if (clnt.proxy == null) { System.Console.WriteLine(" -- Could not locate server -- "); return; } Console.Write("\n To call remote object enter string"); Console.WriteLine("\n Just hit enter to quit:"); try { while(true) { string test = "..."; Console.Write("\n > "); test = Console.ReadLine(); if(test == "") break; // invoke remote object string retVal = clnt.proxy.say(test); // display string returned from remote object Console.Write(" "); Console.Write(retVal); } catch(System.Exception e) { Console.WriteLine(e.Message); } Here, client accesses remote object via its proxy.

.Net Remoting22

.Net Remoting23 Multiple Clients  Remote-able objects have one of three activation attributes: –Client Activated Object is created on first call, then lives a fixed amount of time – its lease – unless it is called again, in which case its lease is extended. Each client gets a new object running on its own thread. –Singlecall each client gets a new copy of the remote-able object on its own child thread, which exists for the duration of a single call. –Singleton All clients get a reference to the same remote-able object operating on the only child thread. Singletons also have a lease on life that is renewed on each subsequent call.

.Net Remoting24 Multiple Clients

.Net Remoting25 Message Passing  Remoting can be used to construct a message-passing system with very little code. –Use a remote-able object for server-side processing. –The client main thread creates a child thread to handle sending and receiving messages. The client threads share two First-In-First-Out (FIFO) queues. To make a request of the server, the client main thread composes a request message and posts it to a sendQ shared with the child thread. The child thread deQs the message and sends it as a parameter in a call to the remote server object. When the server processing is complete, the server’s response message is returned to the child thread. The child thread posts the return value to the RecvQ. The client main tread dequeues the response for processing.

.Net Remoting26 Message Passing Architecture

.Net Remoting27 Other Topics  Prosise discusses: –Asynchronous method calls –Handling remote events with delegates –Declarative configuration (using config files) –Client activated remote objects –Leases control lifetime of singleton and client activated objects. –IIS activation and HTTP channels

.Net Remoting28 Deployment  Configuration files  Server Deployment with Windows Services  Server Deployment with IIS  Client Deployment with IIS

.Net Remoting29 Deployment Issues  Change in server location –Does the client hard-code the location and port of remote objects on the server?  Uses of the application –Will this application be used in other ways? For instance, LAN vs Internet use.  New/additional remotable objects –Will we be adding remotable objects after we have built the application?  Web deployment

.Net Remoting30 Configuration Files  Rather than hard-code the registration of remote objects and their channels, we can use a configuration file.  Using a configuration file allows us to do the following without recompiling the server or client: –Change the type of channel that is used –Add additional remotable objects –Change the lifetime settings of remotable objects –Add message sinks or formatters to the server or client  This functionality is available through the System.Runtime.Remoting assembly.

.Net Remoting31 Configuration Files (cont)  A configuration file is an XML document that is loaded by the server or client.  Use two different configuration files for the client and the server.  On the server, load the configuration file using: RemotingConfiguration.Configure(“MyServer.exe.config”);  On the client, load the configuration file using RemotingConfiguration.Configure(“MyClient.exe.config”);  After loading the configuration file on the client, simply call new on the remotable object class to create a proxy.

.Net Remoting32 Configuration Files (cont)  Content and structure

.Net Remoting33 Configuration Files (cont)  Lifetime –The tag allows you to change the lifetime of your remotable objects. –Valid attributes: leaseTime – This is the initial lease time that an object will have to live before it is destroyed. sponsorshipTimeout – The time to wait for a sponsor’s reply. renewOnCallTime – This is the additional lease time that is added with each call on the remote object. leaseManagerPollTime – Specifies when the object’s current lease time will be checked. –Note that these apply to Singleton and Client-Activated objects only.

.Net Remoting34 Configuration Files (cont)  Channels –The element contains the channels that your application will be using. We declare channels with the tag. –The tag specifies the type, port, and other properties for a particular channel. –Valid attributes: ref – “http” or “tcp” displayName – Used for.NET Framework Configuration Tool type – if ref is not specified, contains namespace, classname, and assembly of the channel implementation. port – server side port number. Use 0 on the client if you want to get callbacks from the server. name – Unique names to specify multiple channels (use “”) priority – Sets priority of using one channel over another.

.Net Remoting35 Configuration Files (cont)  Channels –Valid attributes (cont): clientConnectionLimit – Number of simultaneous connections to a particular server (default = 2) proxyName – name of the proxy server proxyPort – port of the proxy server suppressChannelData – specifies whether a channel will add to the ChannelData that is sent when an object reference is created useIpAddress – specifies whether the channel should use IP addresses in URLs rather than hostname of the server listen – setting for activation hooks into listener service bindTo – used with computers that have multiple IP addresses machineName – overrides useIpAddress rejectRemoteRequests (tcp only) – sets local communication only

.Net Remoting36 Configuration Files (cont) –Providers Sink and formatter providers allow the user to specify the manner in which messages are generated and captured by the framework for each channel. Both the client and server may specify settings for The tags and contain the individual settings for each provider or formatter that you wish to set. You can specify one formatter and multiple provider settings. You must place the settings in the order shown:

.Net Remoting37 Configuration Files (cont) –Example channel entry for a server:

.Net Remoting38 Configuration Files (cont) –Providers (cont) Available attributes for formatters and providers: – ref – “soap”, “binary”, or “wsdl” – type – if ref is not specified, contains namespace, classname, and assembly of the sink provider implementation. – includeVersions (formatter only) – specifies whether version information is included with object requests – strictBinding (formatter only) – specifies whether the server must use an exact type and version for object requests

.Net Remoting39 Configuration Files (cont)  Service –The tag is used in the server’s configuration file to specify the remote objects that will be hosted. –Contains and entries for server-activated objects (SAOs) and client-activated objects (CAOs), respectively. –Valid attributes for type – Specifies the namespace, classname, and assemblyname of the remote object. mode – Singleton or SingleCall objectUri – Important for IIS hosting (URIs must end in.rem or.soap, as those extensions can be mapped into the IIS metabase. displayName – Optional, used by.NET Framework configuration tool. –Valid attributes for type – Specifies the namespace, classname, and assemblyname of the remote object.

.Net Remoting40 Configuration Files (cont)  Client –The tag is used in the client’s configuration file to specify the types of remote objects that it will use. –Contains attribute for the full URL to the server if using CAOs. –Contains and entries for server-activated objects (SAOs) and client-activated objects (CAOs), respectively. –Valid attributes for url – The full URL to the server’s registered object type - Specifies the namespace, classname, and assemblyname of the remote object. displayName – Optional, used by.NET Framework configuration tool –Valid attributes for type – Specifies the namespace, classname, and assemblyname of the remote object.

.Net Remoting41 Configuration Files (cont)  Usage notes: –Errors in your configuration file cause the framework to instantiate a local copy of the remote object rather than a proxy when you call new on it. Check the IsTransparentProxy method to be sure you are using a remote object. –When you specify assembly names in your and, don’t include the extension (.dll or.exe). –You only have to specify the features that you want/need in your configuration file. –You don’t have to use the setting on the client if you use the default “http” or “tcp” channels on the server. You must specify a port on the server.

.Net Remoting42 Server Deployment with IIS  If you are concerned about security, then IIS hosting is the best way to go.  Authentication and encryption features are available through IIS.  Remote objects are now hosted in IIS; there is no Main() in the server.  Updates to the server are easy: just copy over the remote object assembly and web.config file. IIS will automatically read the new data.

.Net Remoting43 Server Deployment with IIS  Procedure: –Create a class library for your remotable objects –Build the assembly for the class library –Create a web.config file for the server –Create a virtual directory on the host machine –Set the desired authentication methods for the directory –Place the web.config file in the virtual directory –Create a /bin directory in the virtual directory –Place the remotable object assembly in the virtual directory –Create a client and configuration file

.Net Remoting44 Client Deployment with IIS  By placing a WinForm application in a virtual directory, we can stream it to clients.  When a URL is selected by a client machine, an HTTP request is sent to the server, which streams the application back to the client.  The application is then stored in the browser cache and also the.NET download cache.  The runtime opens the application automatically and also makes requests for additional assemblies and files as necessary.  Be sure to put any remoting configuration files in the virtual directory with the client application.

.Net Remoting45.Net Remoting The End