Saturday, 1 October 2011

What is the difference between Cache object and Application object?

               The main difference between the Cache and Application objects is that the Cache object provides cache-specific features, such as dependencies and expiration policies

  How to get access to Cache object ?

              The Cache object is defined in the System.Web.Caching namespace. You can get a reference to the Cache object by using the Cache property of the HttpContext class in the System.Web namespace or by using the Cache property of the Page object

 

What is a Web Service?


                         Web Services are business logic components which provide functionality via the Internet using standard protocols such as HTTP. Web Services uses Simple Object Access Protocol (SOAP) in order to expose the business functionality.SOAP defines a standardized format in XML which can be exchanged between two entities over standard protocols such as HTTP. SOAP is platform independent so the consumer of a Web Service is therefore completely shielded from any implementation details about the platform exposing the Web Service. For the consumer it is simply a black box of send and receive XML over HTTP. So any web service hosted on Windows can also be consumed by UNIX and LINUX platform.

How can you specify remoting parameters using Config files?


Both remoting server and remoting client parameters can be provided through config files. Below is a sample of server config file which provides all remoting parameter values which we where providing through code.

<configuration>
<system.runtime.remoting>
<application name="Server">
<service>
<wellknown mode="SingleCall" type="Server.ClsServer, Server"
objectUri="RemoteObject" />
</service>
<channels>
<channel ref="tcp server" port="9000" />
</channels>
</application>
</system.runtime.remoting>
</configuration>

Later this config file can be loaded using the following code.
 
RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ApplicationBase
& "Server.config")

Same way we also have client.config file for loading the client remoting parameters.

<configuration>
<system.runtime.remoting>
<application name="Client">
<client url="tcp://localhost:9000/RemoteObject">
<wellknown type="CommonInterface.Icommon, Icommon"
url = "tcp://localhost:9000/Server/RemoteObject"/>
</client>
<channels>
<channel ref="tcp client" />
</channels>
</application>
</system.runtime.remoting>
</configuration>
client remoting can then load the configuration file by using :


Dim IobjCommon As CommonInterFace.Icommon
Dim StrData As String
Dim objServiceEntries As WellKnownClientTypeEntry()
RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ApplicationBase
& "Client.config")
objServiceEntries = RemotingConfiguration.GetRegisteredWellKnownClientTypes()
IobjCommon = Activator.GetObject(GetType(Icommon), objServiceEntries(0).ObjectUrl.ToString())
StrData = IobjCommon.GetValue()
Console.WriteLine(" Serve side Data is " & StrData)
Console.ReadLine()

Describe in detail Basic of SAO architecture of Remoting?


Remoting has at least three sections :
  Common Interface which will be shared between them.
  Server.
  Client.
Here is an explanation of the process:
  First important section is the common interface between Server and Client. For sample project interface
is very simple with only two methods : SetValue and GetValue. 

Public Interface InterFaceRemoting
Sub SetValue(ByVal value As String)
Function GetValue() As String
End Interface
  Second important section is the server. In this sample server is using HTTP channel and the server object is singleton.

Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Channels
Imports InterFaceRemoting
Public Class RemotingServer Inherits MarshalByRefObject
Implements InterFaceRemoting.InterFaceRemoting
Private strData As String
Public Function GetValue() As String Implements
InterFaceRemoting.InterFaceRemoting.GetValue
Return strData
End Function
Sub New()
strData = "testing.."
End Sub
Public Sub SetValue(ByVal value As String) Implements
InterFaceRemoting.InterFaceRemoting.SetValue
strData = value
End Sub
End Class
Module ModuleRemotingStartUp
Sub Main()
Dim objHttpChannel As HttpChannel
Console.WriteLine("Server Started...")
objHttpChannel = New HttpChannel(1234)
ChannelServices.RegisterChannel(objHttpChannel)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(RemotingServer),
"RemoteObject", WellKnownObjectMode.Singleton)
Console.WriteLine("Server registered and listening waiting for clients...")
Console.ReadLine()
End Sub
End Module

In the code above, Channel object is created and registered. Server then hosts the object so that client can connect to it. This is the time when we specify what mode the server object will be created i.e. Singleton or SingleCall. This is done by the following below given code. Note in sample we are hosting the server object in singleton mode that means that the same object
will be shared between all clients. Also note the server object is implementing "InterFaceRemoting" and inheriting from "MarshalByRefObject".
RemotingConfiguration.RegisterWellKnownServiceType(GetType(RemotingServer),
"RemoteObject", WellKnownObjectMode.Singleton)
  In the last section the client will connect to this hosted remoting object.

Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Channels
Imports InterFaceRemoting
Module ModuleStartClient
Sub Main()
Dim objHttpChannel As New HttpChannel
Dim objRemoting As InterFaceRemoting.InterFaceRemoting
ChannelServices.RegisterChannel(objHttpChannel)
objRemoting =
CType(Activator.GetObject(GetType(InterFaceRemoting.InterFaceRemoting),
"http://localhost:1234/RemoteObject"),
InterFaceRemoting.InterFaceRemoting)
Console.WriteLine("Referenced the main object.... Now displaying Data")
Console.WriteLine("Value on server :- " & objRemoting.GetValue.ToString())
Console.WriteLine("Press enter to Terminate")
Console.ReadLine()
End Sub
End Module
  Finally you need to run server and then client.

What are two different types of remote object creation mode in .NET?


There are two different ways in which object can be created using Remoting:
  SAO (Server Activated Objects) also called as Well-Known call mode.
  CAO (Client Activated Objects).
SAO has two modes "Single Call" and "Singleton". With Single Call object the object is created with every method call thus making the object stateless. With Singleton the object is created only once and the object is shared with all clients.
CAO are stateful as compared to SAO. In CAO the creation request is sent from client side. Client holds a proxy to the server object created on server