Why use stored procedures?

0 comments
stored procedure is a subroutine available to applications accessing a relational database system. Stored procedures (sometimes called a procsprocStoProStoredProc, or SP) are actually stored in the database data dictionary.
Typical uses for stored procedures include data validation (integrated into the database) or access control mechanisms. Furthermore, stored procedures are used to consolidate and centralize logic that was originally implemented in applications. Extensive or complex processing that requires the execution of several SQL statements is moved into stored procedures, and all applications call the procedures. One can use nested stored procedures, by executing one stored procedure from within anot
Stored procedures are similar to user-defined functions (UDFs). The major difference is that UDFs can be used like any other expression within SQL statements, whereas stored procedures must be invoked using the CALL statement.[1]





Definition: Stored procedures are precompiled database queries that improve the security, efficiency and usability of database client/server applications. Developers specify a stored procedure in terms of input and output variables. They then compile the code on the database platform and make it available to aplication developers for use in other environments, such as web applications. All of the major database platforms, including Oracle, SQL Server and MySQL support stored procedures. The major benefits of this technology are the substantial performance gains from precompiled execution, the reduction of client/server traffic, development efficiency gains from code reuse and abstraction and the security controls inherent in granting users permissions on specific stored procedures instead of the underlying database tables.

Stored procedures offer several distinct advantages over embedding queries in your Graphical User Interface (GUI). Your first thought may be: "Why tolerate the added development overhead?" After seeing the advantages, you may change your mind.
Advantage 1: Stored procedures are modular. This is a good thing from a maintenance standpoint. When query trouble arises in your application, you would likely agree that it is much easier to troubleshoot a stored procedure than an embedded query buried within many lines of GUI code.
Advantage 2: Stored procedures are tunable. By having procedures that handle the database work for your interface, you eliminate the need to modify the GUI source code to improve a query's performance. Changes can be made to the stored procedures--in terms of join methods, differing tables, etc.--that are transparent to the front-end interface.
Advantage 3: Stored procedures abstract or separate server-side functions from the client-side. It is much easier to code a GUI application to call a procedure than to build a query through the GUI code.
Advantage 4: Stored procedures are usually written by database developers/administrators. Persons holding these roles are usually more experienced in writing efficient queries and SQL statements. This frees the GUI application developers to utilize their skills on the functional and graphical presentation pieces of the application. If you have your people performing the tasks to which they are best suited, then you will ultimately produce a better overall application.
In short, queries are best handled via stored procedures. While the initial development overhead is greater, you will more than make up for the investment down the line.


Example:

CREATE PROCEDURE sp_GetInventory
@location varchar(10)
AS
SELECT Product, Quantity
FROM Inventory
WHERE Warehouse = @location

.NET Assemblies, GAC, Versioning, Manifests and Deployment

0 comments
A .NET application is composed of three primary entities: assemblies, modules and types. An Assembly is the primary unit of deployment. The individual files that make up a .NET application are call modules. Types are the basic unit of encapsulating data and behavior behind an interface composed of public fields, properties, and methods.
Assemblies
An assembly is used by the .NET CLR (Common Language Runtime) as the smallest unit for: deployment; version control; security; type grouping and code reuse. Assemblies consists of a manifest and one or more modules and/or files like HTML, XML, images, video clips,...
An assembly can be thought of as a logical DLL and must contain a single manifest and may optionally contain type meta data, MSIL (Microsoft Intermediate Language) and resources.
Assemblies come in 2 flavors: application private and shared. Application private assemblies are used by one application only. This is the default style of assembly. Such assemblies must reside in the application folder.
Shared assemblies are meant to be used by more than one application. They must have a globally unique name and must be defined in the GAC (Global Assembly Cache). To learn more about viewing the GAC click here.
Manifest (Assembly Meta Data)
The manifest makes an assembly self describing and can be viewed with the IL Disassembler - Intermediate Language Disassembler. The IL Disassembler (Ildasm.exe) is included in the .NET Framework SDK and runs from a command line.
The manifest identifies the assembly, describes its security requirements, lists other assemblies it depends on, and lists all of the types and resources exposed by the assembly. If any of the resources exposed by the assembly are localized, the mainfest contains the default culture (language, currency, date/time format, etc.) the application will target.
The manifest will be discussed further later on.
Modules
A module is either a DLL or an EXE (Windows Portable Executable - PE) file. It contains IL (Intermediate Language), associated Meta Data and optionally the assembly's manifest. IL is a platform independent way of representing the managed code within an application. Before the managed code is executed the CLR compiles the associated IL into native machine code.
Types
A type describes the encapsulation of data and an associated set of behaviors. Types are scoped at the assembly level. Reference types can be thought of as classes and value types as structures (VB6 user-defined types).
Types have properties, methods and fields. Fields are variables used to hold values. Properties are like fields but with code behind them. Methods are the public procedures that define the behavior of the class.
Versioning
The CLR supports versioning of shared assemblies via the GAC and allows for side by side versioning and Automatic QFEs (hotfixes). Side by side versioning means multiple versions of the same component can be stored in the GAC at the same time. Automatic QFE support means that if a compatible newer version of a component is available, the CLR will use it.
Manifest - Revisited
The manifest contains several sections: Identity, Referenced Assemblies, File List and Custom Attributes. The first two sections are discussed subsequently.
Identity Section of the Manifest
The Identity section uniquely identifies an assembly. To find it using the IL disassembler look for a .assembly directive in the manifest with out the extern directive. Example:
.assembly Microsoft.VisualBasic
The CLR appends .dll to the name (ex. Microsoft.VisualBasic) to find the actual file containing the assembly.
The version directive specifies the version of the assembly in major version : minor version : build : revision format:
.assembly Microsoft.VisualBasic
.ver 7:0:0:0
Assemblies with the same name but different versions (major and minor version numbers) are treated as completely different assemblies by the CLR.
The Identity section optionally contains a strong name for private assemblies. Strong names are required for shared assemblies. A strong name uses public/private key encryption to uniquely identify the assembly and distinguish between assemblies with the same name.
A public key is generated by the assembly author using the SN tool (sn.exe) included in the .NET Framework SDK. The public key is stored in the manifest and a signature of the file containing the assembly's manifest is stored in the resultant PE file. The CLR uses these two signatures to resolve type references to ensure the correct assembly is loaded at runtime. The public key is stored using this directive:
.publickeytoken = (xxxxx)
Optionally contained in the Identity section is the culture which defines the country and language the assembly is targeted for. The .locale directive is used for this purpose. Culture-neutral assemblies can be used for any culture.
Referenced Assemblies Section of the Manifest
The Referenced Assemblies section holds information about all assemblies referenced by your assembly. The .assembly directive accomplishes this:
.assembly extern 
.publickeytoken = (xx xx xx)
.ver 1:0:241:0
As stated before, the CLR appends .DLL to the name to find the physical file. If the referenced assembly has a strong name, the .publickeytoken will contain a hash of the referenced assemblies public key. Version and culture directives are used for externally referenced assemblies as described above.
Deployment
Recall, assemblies can be application private or shared. Application private assemblies must reside in the application folder and do not need a strong name. They only need a name and version in the Identity section of the manifest. If a strong name exists the CLR checks the strong name of the assembly and referenced assemblies to see if they match.
Shared assemblies are used by many applications and must have a globally unique name based on their strong name. Their information is stored in the GAC which is typically the Assembly folder in the Windows directory.
To learn more about viewing the GAC, click here.
Deployment
Applications can be deployed in an isolated fashion termed application isolation where the application is self contained and independent. All modules of an application are managed by the application. If a component is used by another application, even if it's the same version, that application has its own copy. Thus each application can be installed and removed independently. .NET provides for this using application private assemblies.
Side by side execution is when multiple versions of the same assembly can execute at the same time on the same PC or within the same process. Again, the CLR allows for this. Recall, a version number has four parts. The major and minor parts determine if a component version is compatible with a prior version. If they differ, they are not compatible. If only the build and revision numbers differ, the components are compatible. This is called Quick Fix Engineering (QFE).
Unless told otherwise, .NET uses the default versioning policy to decide what version of a referenced assembly to use. If the referenced assembly doesn't have a strong name it is assumed to be application private and to reside in the application folder. The CLR will load it regardless of whether its version matches what's in the calling assembly's manifest. Thus, version numbers of application private assemblies are not checked. If the referenced assembly is not found in the application folder, an error occurs.
Quick Fix Engineering
If a referenced assembly has a strong name the load process is as follows:
  • Assembly configuration files (discussed later) are examined to see what version of a referenced assembly to load.

  • The CLR checks if the assembly was loaded in a previous call. If so, it is used.

  • If the assembly isn't loaded the GAC is queried for a match and if found that's what's loaded.

  • If a configuration file has a codebase entry for the assembly the file specified by this entry is used.

  • If none of the above exist, the CLR looks for the referenced assembly starting in the application folder.

  • If still not found, the CLR asks the Windows Installer service if it has the assembly. If so, the assembly is installed and this is the assembly used. This is call install on demand.

  • If the assembly still cannot be found, an error is raised.
Just because a referenced assembly has a strong name doesn't mean it has to be deployed to the GAC. A developer can install a known good version with the application. The GAC is checked to see if it has an assembly with a higher build.revision number. This allows deployment of an updated assembly without having to re-install or rebuild the application. This is known as Automatic Quick Fix Engineering Policy.
Configuration Files
Three configuration files can alter the above policy. The application configuration file which resides in the application folder and has the same name as the application file with .config appended to it (Ex: myExe.exe.config) is, as the name implies, application specific.
The machine configuration file named machine.config and located in the \Config folder overrides all application configuration file(s) on a machine. Lastly the security configuration file allows granting/denying access to resources by an assembly.
Configuration files are XML files used to override the default policy used by the CLR. They have a <startup> section which specifies the version of the CLR to use for the application. This is because different versions of the .NET runtime can run side by side on a machine. Click here for more info.
The <runtime> section has a few key elements that can specify the version of an assembly to use either all the time or to replace a specific version of the assembly.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas=microsoft-com:asm.v1">
<dependentAassembly>
<assemblyIdentity name="AssemblyName"
publickeytoken="b8838383d8s88"
culture="en-us"/>
<bindingRedirect oldVersion="*"
newVersion="2.0.34.0"/>
</dependentAassembly>
</assemblyBinding>
</runtime>
</configuration>
When the CLR resolves the reference to AssemblyName it loads version 2.0.34.0 instead of the version stated in the manifest. Instead of replacing all versions with 2.0.34.0 the oldVersion element can specify the exact version to replace.
The exact location of the assembly to load can be specified with the <codeBase> element. Thus, on demand downloading can be employed to distribute an application and have an externally referenced assembly downloaded the first time it is used.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas=microsoft-com:asm.v1">
<dependentAassembly>
<assemblyIdentity name="AssemblyName"
publickeytoken="b8838383d8s88"
culture="en-us"/>
<codeBase version="2.0.34.0"
href="http://www.thescarms.com/mydll.dll"/>
</dependentAassembly>
</assemblyBinding>
</runtime>
</configuration>
An application configuration file can also specify the search path for the CLR to use. By default the CLR looks in the application folder and not sub folders. This can be changed by specifying a relative path or list of relative folders separated by semi-colons.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas=microsoft-com:asm.v1">
<probing privatePath="myfolder"/>
</assemblyBinding>
</runtime>
</configuration>
The CLR will look in the application's folder, all specified sub folders and a sub folder with the same name as the assembly name. Further, it a culture is used, the CLR will look in a culture specific sub folder of each of the directories it looks in. For example, if an assembly named "AssemblyName" resides in "C:\MyApp" and the culture is "en" the CLR will look in:
C:\MyApp
C:\MyApp\en
C:\MyApp\en\AssemblyName
C:\MyApp\myfolder
C:\MyApp\myfolder\en\AssemblyName

.NET Remoting Versus Web Services

0 comments
With the advent of .NET and the .NET Framework, Microsoft introduced a set of new technologies in the form of Web services and .NET remoting. .NET remoting and ASP.NET Web services are powerful technologies that provide a suitable framework for developing distributed applications. It is important to understand how both technologies work and then choose the one that is right for your application.
The Web services technology enables cross-platform integration by using HTTP, XML and SOAP for communication thereby enabling true business-to-business application integrations across firewalls. Because Web services rely on industry standards to expose application functionality on the Internet, they are independent of programming language, platform and device.
Remoting is .a technology that allows programs and software components to interact across application domains, processes, and machine boundaries. This enables your applications to take advantage of remote resources in a networked environment.
Both Web services and remoting support developing distributed applications and application integration, but you need to consider how they differ before choosing one implementation over the other. In this article, I will show the differences between these two technologies. I will present samples for each type of implementation and identify when to use which technology.

DCOM

If you are a real Microsoft platform developer then you have done some work on COM and interface based components. When it comes to distributing your program logic, you are almost tied to Distributed COM (DCOM).
DCOM is a very proprietary RPC-based communication protocol for COM-based distributed component architectures. Even though DCOM allows us to create scalable and reliable architectures in the Intranet environment, there are a lot of problems with DCOM when you try to integrate with different platforms and technologies in an Internet environment.

A Look at .NET Remoting

.NET Remoting uses a flexible and extremely extensible architecture. Remoting uses the .NET concept of an Application Domain (AppDomain) to determine its activity. An AppDomain is an abstract construct for ensuring isolation of data and code, but not having to rely on operating system specific concepts such as processes or threads. A process can contain multiple AppDomains but one AppDomain can only exist in exactly one process. If a call from program logic crosses an AppDomain boundary then .NET Remoting will come into place. An object is considered local if it resides in the same AppDomain as the caller. If the object is not in the same appdomain as the caller, then it is considered remote.
In .NET remoting, the remote object is implemented in a class that derives from System.MarshalByRefObject. The MarshalByRefObject class provides the core foundation for enabling remote access of objects across application domains. A remote object is confined to the application domain where it is created. In .NET remoting, a client doesn't call the methods directly; instead a proxy object is used to invoke methods on the remote object. Every public method that we define in the remote object class is available to be called from clients.

When a client calls the remote method, the proxy receives the call, encodes the message using an appropriate formatter, then sends the call over the channel to the server process. A listening channel on the server appdomain picks up the request and forwards it to the server remoting system, which locates and invokes the methods on the requested object. Once the execution is completed, the process is reversed and the results are returned back to the client.
Out of the box, the remoting framework comes with two formatters: the binary and SOAP formatters. The binary formatter is extremely fast, and encodes method calls in a proprietary, binary format. The SOAP formatter is slower, but it allows developers to encode the remote messages in a SOAP format. If neither formatter fits your needs, developers are free to write their own and plug it in as a replacement.

Different Types of Remote Objects

The remoting infrastructure allows you to create two distinct types of remote objects.
  1. Client-activated objects - A client-activated object is a server-side object whose creation and destruction is controlled by the client application. An instance of the remote object is created when the client calls the new operator on the server object. This instance lives as long as the client needs it, and lives across one to many method calls. The object will be subject to garbage collection once it's determined that no other clients need it.
  2. Server-activated objects - A server-activated object's lifetime is managed by the remote server, not the client that instantiates the object. This differs from the client-activated object, where the client governs when the object will be marked for finalization. It is important to understand that the server-activated objects are not created when a client calls New or Activator.GetObject. They are rather created when the client actually invokes a method on the proxy. There are two types of server activated objects. They are:
    • Single call . Single-call objects handle one, and only one, request coming from a client. When the client calls a method on a single call object, the object constructs itself, performs whatever action the method calls for, and the object is then subject to garbage collection. No state is held between calls, and each call (no matter what client it came from) is called on a new object instance.
    • Singleton - The difference in a singleton and single call lies in lifetime management. While single-call objects are stateless in nature, singletons are stateful objects, meaning that they can be used to retain state across multiple method calls. A singleton object instance serves multiple clients, allowing those clients to share data among themselves.

A Look At ASP.NET Web Services

With the arrival of .NET, creating an ASP.NET Web service is a breezy experience with the .NET framework taking away all the complexities in creating and consuming Web services. To create a Web service, all you need to do is create a Web service class that derives from the System.Web.Services.WebService class and decorate the methods (that you want to expose as Web services) with the WebMethod attribute. Once this is done, these methods can be invoked by sending HTTP requests using SOAP.
Consuming a Web service is very straightforward too. You can very easily create a proxy class for your Web service using either wsdl.exe utility or the Add Web Reference option in VS.NET. The Web service proxy hides all the network and marshaling plumbing from the application code, so using the Web service looks just like using any other local object.


Click here for larger image

As you can see from the above diagram, the client proxy receives the request from the client, serializes the request into a SOAP request which is then forwarded to the remote Web service. The remote Web service receives the SOAP request, executes the method, and sends the results in the form of a SOAP response to the client proxy, which deserializes the message and forwards the actual results to the client.

ASP.NET Web Services Vs .NET Remoting

Now that we have understood the basic concepts of .NET remoting and Web services, let us identify the differences between these two technologies. For this, I present different factors such as performance, state management, etc and then identify which technology to use in what situations.

Performance

In terms of performance, the .NET remoting plumbing provides the fastest communication when you use the TCP channel and the binary formatter. In the case of Web services, the primary issue is performance. The verbosity of XML can cause SOAP serialization to be many times slower than a binary formatter. Additionally, string manipulation is very slow when compared to processing the individual bits of a binary stream. All data transported across the wire is formatted into a SOAP packet. However if your Web service performs computation intensive operations, you might want to consider using caching to increase the performance of your Web service on the server side. This will increase the scalability of the Web service, which in turn can contribute to the increase in performance of the Web service consumers. A remoting component, using the TCP channel and the binary formatter, provides the greatest performance of any remoting scenario, primarily because the binary formatter is able to serialize and deserialize data much faster.
If you use .NET remoting with a SOAP formatter, you will find that the performance provided by ASP.NET Web services is better than the performance provided by NET remoting endpoints that used the SOAP formatter with either the HTTP or the TCP channel. However the .NET remoting provides clear performance advantages over ASP.NET Web services only when you use TCP channels with binary communication.

State Management

Web services are a stateless programming model, which means each incoming request is handled independently. In addition, each time a client invokes an ASP.NET Web service, a new object is created to service the request. The object is destroyed after the method call completes. To maintain state between requests, you can either use the same techniques used by ASP.NET pages, i.e., the Session and Application objects, or you can implement your own custom solution. However it is important to remember that maintaining state can be costly with Web services as they use extensive memory resources.
.NET remoting supports a range of state management options that you can choose from. As mentioned before, SingleCall objects are stateless, Singleton objects can share state for all clients, and client-activated objects maintain state on a per-client basis. Having three types of remote objects (as opposed to one with Web services) during the design phase helps us create more efficient, scalable applications. If you don't need to maintain state, use single-call objects; if you need to maintain state in a small section of code, use single call and singletons together. The ability to mix and match the various object types facilitates creation of solid architectural designs.

Security

.NET remoting plumbing does not provide out of the box support for securing cross-process invocations. However a .NET remoting object hosted in IIS, can leverage all the same security features provided by IIS. If you are using the TCP channel or the HTTP channel hosted in a container other than IIS, you have to implement authentication, authorization and privacy mechanisms yourself.
Since ASP.NET Web services are hosted, by default, in IIS, they benefit from all the security features of IIS such as support for secure communication over the wire using SSL, authentication and authorization services.

Reliability

.NET remoting gives you the flexibility to host remote objects in any type of application including a Windows Form, a managed Windows Service, a console application or the ASP.NET worker process. If you host your remote objects in a windows service, or a console application, you need to make sure that you provide features such as fault tolerance within your hosting application so that the reliability of the remote object is not compromised. However if you do host remote objects in IIS, then you can take advantage of the fact that the ASP.NET worker process is both auto-starting and thread-safe. In the case of ASP.NET Web services, reliability is not a consideration as they are always hosted in IIS, making it easy for them to take advantage of the capabilities provided by IIS.

Extensibility

Both the ASP.NET Web services and the .NET remoting infrastructures are extensible. You can filter inbound and outbound messages, control aspects of type marshaling and metadata generation. .NET remoting takes extensibility to the next level allowing you to implement your own formatters and channels.
Since ASP.NET Web services rely on the System.Xml.Serialization.XmlSerializer class to marshal data to and from SOAP messages at runtime, we can very easily customize the marshaling by adding a set of custom attributes that can be used to control the serialization process. As a result, you have very fine-grained control over the shape of the XML being generated when an object is serialized.

Ease of programming and deployment

In this section, we will consider a simple remoting object and an ASP.NET Web service to understand the complexities involved in creating and consuming them. We will start off by creating a simple remote object.

Creating a remote object

Creating a remoting object is a simple process. To create a remote object, you need to inherit from MarshalByRefObject class. The following code shows a remotable class.
using System;
namespace RemoteClassLib
{
public class MyRemoteObject : System.MarshalByRefObject
{
public MyRemoteObject()
{
Console.WriteLine("Constructor called");
}

public string Hello(string name)
{
Console.WriteLine("Hello Called");
return "Hello " + name;
}
}
}
The above code is very simple and straightforward. We start off by defining a class that inherits from MarshalByRefObject. After that we add code to the constructor of the class to write out a message to the console. Then we have a method named Hello that basically takes a string argument and appends that with the string and returns the concatenated value back to the caller. Once the remote object is created, the next step is to create a host application that hosts the remote object. For the purposes of this article, we will create a console application that reads the details of the remote object from its configuration file.
using System;
using System.Runtime.Remoting;

namespace RemoteClassLibServer
{
class RemoteServer
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Configure(
"RemoteClassLibServer.exe.config");
Console.WriteLine("Press return to Exit");
Console.ReadLine();
}
}
}
In the main method, we just read the configuration settings from the configuration file using the RemotingConfiguration.Configure method and wait for the client applications to connect to it.
The configuration file used by the above hosting application looks like the following. In the configuration file, we specify that we want to expose the remote object using the TCP channel by using the channel element.
<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
<system.runtime.remoting>
<application name="RemoteClassLibServer">
<service>
<wellknown mode="SingleCall"
type="RemoteClassLib.MyRemoteObject,RemoteClassLib"
objectUri="MyRemoteObject">
</wellknown>
</service>
<channels>
<channel ref="tcp server" port="9000"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Once the hosting application is started, then client applications can start creating instances of the remote object and invoke its methods. In the next section, we will understand the processes involved in creating an ASP.NET Web service.

Creating an ASP.NET Web Service

As mentioned before, creating an ASP.NET Web service is pretty easy in VS.NET. Select the ASP.NET Web Service template using Visual Studio.NET New Project dialog box. Enter the name of the project and click OK to create the project. Once the project is created, modify the default service1.asmx file to look like the following.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace XmlWebServicesExample
{

public class Service1 : System.Web.Services.WebService
{
public Service1()
{
}

[WebMethod (EnableSession=true)]
public string HelloWorld()
{
return "Hello World";
}
}
}
As you can see from the above, the Web service class named Service1 is derived from System.Web.Services.WebService. Inheriting from the WebService class is optional and it is used to gain access to common ASP.NET objects like Application, Session, User, and Context. Then we also add a method named HelloWorld that basically returns a simple string back to the callers of the Web service. In the WebMethod attribute of the HelloWorld method, we also specify that we want to enable session state for our ASP.NET Web service by setting the EnableSession attribute to true.

Creating the consumer for the ASP.NET Web Service

You can consume the Web service by using the Add Web Reference option in VS.NET to create a proxy for the Web service. When you create a Web reference, the VS.NET IDE creates a proxy for you based on the WSDL file published by the Web service. Once the proxy is generated, you can treat the proxy class methods as if they are the actual Web service methods. At runtime, when the proxy class methods are invoked, they will connect to the actual Web service, invoke the Web service method, retrieve the results returned by the Web service and hand it back to the consumers. The following screenshot shows how to use the Add Web Reference option to create a proxy for the Web service.


Click here for larger image

So far, we have seen the steps involved in creating a .NET remoting object and an ASP.NET Web service. As can be seen from the above code, ASP.NET Web services are very easy-to-create. Consuming ASP.NET Web service is also a very simple process due to the excellent Web service support provided by Visual Studio.NET. With .NET remoting, you need to create the remote object first and then write a hosting application (assuming that you are not using IIS) to expose that remote object. You also need to make sure that the information about the remote object is retrieved from the configuration file to allow for extensibility in the future. If you all these factors into consideration, you will agree that .NET remoting objects are complex to develop and deploy.

Type Fidelity

ASP.NET Web services favor the XML schema type system, and provide a simple programming model with broad cross-platform reach. .NET remoting favors the runtime type system, and provides a more complex programming model with much more limited reach. This essential difference is the primary factor in determining which technology to use.

Putting it all together

So far, we have looked at the differences between these two technologies. Let us summarize the difference in a table.
ASP.NET Web Services .NET Remoting
Protocol Can be accessed only over HTTPCan be accessed over any protocol (including TCP, HTTP, SMTP and so on)
State Management Web services work in a stateless environmentProvide support for both stateful and stateless environments through Singleton and SingleCall objects
Type System Web services support only the datatypes defined in the XSD type system, limiting the number of objects that can be serialized. Using binary communication, .NET Remoting can provide support for rich type system
Interoperability Web services support interoperability across platforms, and are ideal for heterogeneous environments. .NET remoting requires the client be built using .NET, enforcing homogenous environment.
Reliability Highly reliable due to the fact that Web services are always hosted in IISCan also take advantage of IIS for fault isolation. If IIS is not used, application needs to provide plumbing for ensuring the reliability of the application.
Extensibility Provides extensibility by allowing us to intercept the SOAP messages during the serialization and deserialization stages. Very extensible by allowing us to customize the different components of the .NET remoting framework.
Ease-of-Programming Easy-to-create and deploy. Complex to program.
Though both the .NET Remoting infrastructure and ASP.NET Web services can enable cross-process communication, each is designed to benefit a different target audience. ASP.NET Web services provide a simple programming model and a wide reach. .NET Remoting provides a more complex programming model and has a much narrower reach.
As explained before, the clear performance advantage provided by TCPChannel-remoting should make you think about using this channel whenever you can afford to do so. If you can create direct TCP connections from your clients to your server and if you need to support only the .NET platform, you should go for this channel. If you are going to go cross-platform or you have the requirement of supporting SOAP via HTTP, you should definitely go for ASP.NET Web services.

Combination of .NET Remoting and ASP.NET Web Services in Action



Click here for larger image

So far, we have understood how the .NET remoting and ASP.NET Web services technologies differ in implementation. We have also had a detailed look at different factors to understand what technology to choose in what situation. Even though these two technologies are meant for different purposes, there are times where you will be able to use the combination of these technologies in your application. For example, in an application scenario where you are trying to address the needs of both internet and intranet clients, you might consider using both .NET remoting and Web services as shown in the above diagram. For the intranet .NET clients, you can use .NET remoting to enable cross appdomain communication. For the internet clients, you can expose the same functionality as Web services, allowing client applications running in different platforms to take advantage of the Web service.

Conclusion

Both the .NET remoting and ASP.NET Web services are powerful technologies that provide a suitable framework for developing distributed applications. It is important to understand how both technologies work and then choose the one that is right for your application. For applications that require interoperability and must function over public networks, Web services are probably the best bet. For those that require communications with other .NET components and where performance is a key priority, .NET Remoting is the best choice. In short, use Web services when you need to send and receive data from different computing platforms, use .NET Remoting when sending and receiving data between .NET applications. In some architectural scenarios, you might also be able to use.NET Remoting in conjunction with ASP.NET Web services and take advantage of the best of both worlds.

.Net Interview Quations

0 comments
Question 1. What technologies you worked for?
Answer. C#, VB, Oracle , SQL Server , ASP.NET, JavaScript
Question 2. Lets start with C#, What is modularization?
Answer. Modularization is dividing functionality into different small modules, so that we can reuse the functionality and make it simple to use.
Question 2. Any other use of modularization and Layered application?
Answer. We can add layer to keep different group of functionalities different. and changing one layer does not effect others.
Question 3. Where does the object and its internal variable int i and string s store, in heap or in stack.
Answer. i think int goes to stack
Question 4. What is garbage collector?
Answer. it used to release the memory. and run in  non deterministic manner.
Question 5. Can we run Garbage collector manually and its recommended?
Answer. Yes we can by gc.collect(), it is not recommended.
Question 6. What is overloading and overriding?
Answer. overriding is having same method in base and drive class and deciding at runtime which one to call.
Question 7. What is difference between the runtime polymorphism and overriding.
Answer. both are same.
Question 2. Difference between string builder and string?
Answer. string builder is mutable and string immutable.
Question 2. can we pass object with ref parameter like fun(ref Obj)?
Answer.yes
Question 2.  what is difference between fun(obj) and fun(ref obj)?
Answer. by passing obj we are directly passing object while using ref it passes the address of object.
Question 2. if we have two function abc(int a, int b) and abc(int a, int b, int c) in base class and we derive it in drive class and implement it. in drive class it is overloading or overriding?
Answer. both overloading and overriding.
Question 2. can we have multiple try blocks, can we have multiple catch blocks, can we have multiple finally blocks?
Answer. multiple try yes separate blocks, multiple catch -yes, multiple finally - no
Question 2. What is cluster index and noncluster index ?
Answer. cluster index is physical sorting on table while non cluster index is logical sorting on table.
Question 2. we have a query,
select a, b from table1
where a=a1 and b=b1 and c= c1
on what column will you define the index?
Answer. a, b
Question 2. we have a table empl
emp_id, salary, division
get the employee list whose salary is greater than the average salary of their division?
Answer.
Question 2. there is two tables
emp_id, salary, division_id - emp table
division_id , div_name - div table
get the maximum salary if every division?
Answer.
Question 2. What patterns you used in C# code?
Answer. Singleton, facade
Question 2. Write a code to implement a singleton pattern?
Answer.
Question 2. write a code to check balance brackets in a string? ((()))
Answer.

Question. Lets start with .NET, What is .NET framework?
Answer. Its a platform to run .NET application, where .net applications can use .net resources.
Question. What is DLL?
Answer. Dynamic link libraries, kind of exe file.
Question. What is manifest?
Answer. Contains Details about assembly. like reference, versions, resources and type.

Question. What types of assemblies are there and what is difference?
Answer. Private and public
private is private to application and kept in local application folder
public assemblies are shared among the applications and kept in GAC.
Question. Suppose there is two versions of a assembly, how your application will decide which version to use?
Answer. In web.config under binding give old version and new version
Q. Any other way to do versioning in GAC?
Answer. Find it out.
Q. What is strong type and loose type ?
Answer. its a language property. The language who provide variable data type declaration called loose type like vb and JavaScript provide var type variable declaration while C# not. so C# is strong type language.

 

C# interview Questions

Question. What collection type you used?
Answer. ArrayList
Question. What is difference between arraylist and array?
Answer. Array can store single data type and inserting will cost more, while in array list you can store multiple datatypes and inserting and removing element is easy.
Question. What are delegates?
Answer. it is function to pointer.
Question. What are events?
Answer. events are used with delegate to fire a method on any event occurrence?
Question. What is use of delegate?
Answer. Used of delegate to call a function.
Question. any other use of delegate?
Answer. Find out.
Question. What is difference between list and arraylist.
Answer. list is interface while arraylist is implementation.
Question. What is dataset?
Answer. can contains tables and their relations.
Question. What is datareader?
Answer. Read one row at a time , forward only.
Question. How will you fill dropdown values using datareader?
Answer.
While(datareader.read())
{
bind every value to dropdown
}
or construct a dataset from datareader inside loop and assign to dropdown
Question. What is abstraction?
Answer. Representing complex word in simplified manner.
Question. what is OOPs ?
Answer. programming language fully supported by objects
Question. What is Objects?
Answer. by using Objects we can represent real word easily.
Question. what are the features of objects oriented programming?
encapsulation
overloading
overriding
abstraction
association
generalization
inheritance
data hiding
Question. Have you worked on multithreaded application?
Answer. yes
Question. Describe the multithreaded application ?
Answer. Describe a demo multithread application and why using multithreading.
Question. What is Strongly typed dataset?
Answer. Strongly typed dataset is simple dataset containing the property to have datatype associated with columns and can access column values by using the column names.

Question. What is Deep copy and shallow copy?
Answer. Deep copy, copy the whole object and make a different object, it means it do not refer to the original object while in case of shallow copy the target object always refer to the original object and changes in target object also make changes in original object.
Question. how to Create custom collection?
Answer. using System.Collections namespace we can create the our custom collection classes.
Question. how to Bind grid with business obj?
Answer.  return the dataset or datatable from business object and assign to datasource of grid.
Question. What is Singleton and how to implement locking in singleton pattern?
Answer. Singleton pattern usage a class which can contain only one object through out the application.
class my_Singleton
  {
    private static my_Singleton obj;
    protected my_Singleton
    {
    }
    public static my_Singleton Instance()
    {
      lock{
      if (obj == null)
      {
        obj= new my_Singleton();
      }
    }
      return obj;
    }
  }
Question. What is Typed dataset?
Answer. typed dataset is a normal dataset having property to data type check for Colum values and can access the columns by column names.
Question. What is Using keyword?
Answer. using keyword can be used in two format
1. include the namespace in file
2. handle the idisposable objects inside using block.
iFace obj = new myclass()
Myclass obj1 = new myclass()
Obj.hey();
Obj1.hey();
is the above code is valid?
yes
Question. What is difference between lock vs static locks?
Answer. static lock is applicable to static methods and variables.
Question. What is suppressfinalize?
Answer. We use this method to not to call the finalize method while disposing the objects.
Question. Can we inherit a class from multiple interfaces?
Answer. yes
Question. suppose two interfaces have same method, so how will you  implement these methods in derive class?
Answer. by using interface name
Question. Lets start with .NET, What is CLR and what is the task perform by CLR?
Answer.  CLR stand for Common language runtime. it have the task like
1. running the garbage collector
2. Code verification
3. code access security
4. executing IL
Question. What is assembly? and what is difference between the .dll and .exe?
Answer.  Assembly is a basic unit of .net program and it contains the all .net code, resources, references and versions etc.
.exe and .dll are same while .exe contains executable code and is machine dependent.
Question. if dll and exe files are same it means you can deploy both the files in GAC?
Answer.  No, deploying a exe file does not mean anything because classes and method are exposed in dll only and exe file is pure executable, any application can not call the function of exe file.
Question. How will you deploy the dll file in GAC?
Answer.  first create the strong name for dll and add this sn name key into the application then use gacutil command to register the dll in GAC.
Question. How will you search for a dll in GAC before registering it?
Answer. use process explorer to check the dlls, if you have any other suggestion, Please comment.
Question. What is difference between IL and DLL ?
Answer. DLL contains the IL and other details (metadata) inside.
Question. is exe is machine dependent?
Answer. yes
Question. How to pass the arguments in thread?
by passing the arguments in start() method.
Answer. thread t1 = new thread(new threadstart(obj.abc));
t1.start(21);
Question. What changes will you do if you have to pass string instead of int in thread arguments?
Answer. no chnages in thread while we change the method to receive the string or abject variable.
Question. What are the properties of abstract class?
Answer. 1. abstract class can contain the prototype of method and/or implementation of methods.
2. Direct object of abstract class is not possible.
3. we need to inherit a class and make the object of derive class and can access the abstract class methods.
4. abstract classes can contains the abstract functions.
Question. can we have this definition in abstract class?
abstract class abc
{
abc obj;
}
Answer. yes, we can have same type of obj we can define in and instantiate to derive class.
Question. What pattern you used?
Singleton and facade
Question. describe the facade pattern and use in you project?
Answer. it is used to access the whole subsystem through a system. i used it in a customer class to access the subsystem like sales, billing, invoice etc.
Question. What is singleton pattern?
Answer. creating only one object of a class.
Question. How will you handle deadlock in singleton pattern?
Answer. use lock or monitor to access by single thread.
Question. What is difference between monitor.enter and monitor.tryenter functions?
Answer. monitor.enter waits for the lock until it does not get it.
while monitor.tryenter will request for lock and it return true if get the lock and return false if does not get it and process further statements.
Question. instead of creating a singleton class, suppose i create a static object of singleton class outside the class and use it though out the application, then what is use of singleton class?
Answer. singleton class is use that accidently programmer do not create the another object of the class. it is used in large systems where we expose class and functions though dlls and want to restrict programmer while using this dll do not creating multiple objects.
Question. Why forcing garbage collector to run is not recommended?
Answer. because it sometimes create performance issue and block other threads.

SemanticSpace Telephonic Interview Questions - .NET


Telephonic interviews are sometimes hard to face. but most of the telephonic interviews are easy and this is just verification process that the person is right candidate for the job or not.
My friend gone through a telephonic round of SemanticSpace for software engineer position for .NET.
Question. They started with project, Tell me something about your current project?
Answer. describe your project.
Question. what is OOPs?
Answer. Object oriented programming, represent every thing in a object.
Question. What is polymorphism? what are different types of polymorphism is there?
Answer. polymorphism means different forms, there are two kind of polymorphism
1. static polymorphism (overloading)
2. dynamic polymorphism (overriding)
Question. What is difference between overloading and overriding?
Answer. having same name methods with different parameters is called overloading, while having same name and parameter functions in base and drive class called overriding.
Question. what is static class and what is use of this?
Answer. Static class we define when we do not want to create a object of class, all methods of static class should be static. static class methods and data are specific to class only and not associated to objects.
Question. Can we have a variables inside the interface?
Answer. no, we can have only methods, properties, indexers and enums inside the interface.
Question. Have you used AJAX?
Answer. I have used AJAX using microsoft ajax toolkit.
Question. What is your role in PL/SQL?
Answer. I used to design and write functions, triggers, procedures and packages.
Question. Have you used Queue in Oracle?
Answer. No
Question. What design patterns you used?
Answer. Facade, Prototype, Singleton. proxy , bridge

Polaris Interview Questions - .NET - Telephonic


One of my friend gone through the Polaris telephonic round for .net for software engineer requirement.
Here is some questions from the same telephonic round.
Question 1. What is assembly?
Answer. Assembly is encoded library of .net applications it contains the all source code references and other resources.
Question 2. What is GAC?
Answer. Global assembly cache, is a special area where we generally keep our global assemblies.
Question 3. what is difference between remoting and webservices?
Answer. remoting is used to communication between applications running on same .net platform while webservice is used to communicate between the applications running on
Question 4. how will you implement security in webservices?
Answer. using SOAP
Question 5. how will you authenticate web service?
Answer. Find it out.
Question 6. what is singleton?
Answer. singleton is a design pattern used to design a software. This design pattern allows you to create only one object of a class.
Question 7. How will you implement remoting in C#?
Answer. Read books.
Question 8. What is SAO and CAO?
Answer. Server activate object and client activated object
Question 9. What is marshaling?
Answer. marshaling is used in remoting to transfer data between application.
Question 10. what is WCF and what is difference between WCF and web services?
Answer. WCF is windows communication foundation same as webservices. actually WCF =webservices + remoting

C# - OOPS Interview Questions


Question 1. What is class and objects?
Answer. Class is collection of functions and variables. and object is used to use this template.
Question 2. Can we declare a constructor to private?
Answer. Yes
Question 3. What is the use of constructor ?
Answer. constructor is used to create and instantiate a object.
Question 4. can we specify the accessibility modifier inside the interface?
Answer.  It should be public there is no use of private methods in interface.
Question 5. how to prevent a public class method to be overridden in drive class?
Answer. just make method to sealed.
Question 6. how to stop a class being inherited by another class?
Answer. just make the class sealed. by using sealed keyword.
Question 7.how to prevent a class being instantiated?
Answer. make class abstract or static
Question 8. How to override a private virtual method?
Answer.you can not override a private method.
Question 9.  can you derive a static method of base class in child class?
Answer. no
Question 10.  can you override a normal public method of base class and make it static?
Answer.no , the method signature  should be same to be overridden.
Question 11. what is early and late binding?
Answer. when we call a non virtual method it decide at compile time and this is called early binding. while if method calling decide at runtime is called late binding.
Question 12. Can namespace contain the private class?
Answer. no, having a single private class does not mean anything , it is applicable only in case of nested class.

MakeMyTrip.com .NET Interview Questions | Written Test | Analytical Test | F2F Interview


This question set contains the written test questions and analytical test and Face to Face interview questions.
This interview was held in may 2010 at MakeMyTrip.com. I don't think they give very good salary but you can negotiate with them.

Written test – Fully objective type .NET

This round was fully objective and contains almost 30 objective type of questions in 20 minutes.
Question 1.  Session objects are accessible in?
1. web forms
2. web Farms
3. both
4. none
Answer.  web forms – check once
Question 2. application objects are accessible in?
1. web forms
2. web Farms
3. both
4. none
Answer.  1. web forms
Question 3.  give me three differences between unique key and primary key?
Answer.  1. Primary key is only one in table while unique key can be multiple
2. unique key can be null
3. cluster index create on primary key while non cluster index can be created on non cluster index.
Question 4. which control have the paging?
1. dataset
2. datareader
3. none
4. all
Answer. find out
Question 5. by default security setting in .net?
Answer. anonymous access
Question 6. which file contains  the configuration settings for URI to access in web services?
Answer. .disco (check it once)
like this there were around 30 questions, most of them asp.net questions were there.

Analytics / Aptitude test

this test was totally analytical and contains 40 questions in 30 minutes. you need to have pen and paper with you while attending the test.
you need to give test on http://www.merittrac.com site.
Question 1.  questions like 5 guys are sitting in a round table now A is sitting left to B , C is sitting next to D and then you have to answer some questions.
Question 2.  A English paragraph was given and you need to answer the some questions by reading those questions.
Question 3. 4 figures was given and you need to find the next figure in sequence.
Question 5. The numeric values of a name was given and you need to find the numeric values for the another name.
Question 6. A numeric expression like 3/23*2+44-2 was given and if + is replaced by *, - is replaced by /, /is replaced by + and * is replaced by – what will be the value. around 6-7 questions of this kind.
Question 7. A conclusion was given and statement 1 and statement 2 was given , you need to choose the options on the basis of these
1. Statement 1 is true
2. statement 2 is true
3. statement 1 and statement 2 is true
4. none

Face to Face Technical Round:

this was third round and face to face.
Question 1. Rate yourself in C#, ASP.net, SQL, JavaScript
Answer.
C# - 8
ASP.NET – 8
SQL - 8
Javascript - 8
Question 2. Lets start with ASP.NET, I have a datagrid/Gridview can i have a dropdown inside a  column and binding to different dataset? How
Answer. Yes, keep dropdown in template column
Question 3. How will you fill a dropdown from another dataset and grid from another dataset.
Answer.  First fill the grid with dataset and then datagrid.columns.findcontrol[“dropdown”] find dropdown and add another dataset to it.
Question 4.  How will you add increasing number (index numbers of rows) in datagrid without bringing it from database.
Answer. one method is to add on rowdatabound. find another
Question 5. Suppose there is two button in a datagrid  column. how will you identify which button is clicked?
Answer. by using commadname and commandargument.
Question 6. what is difference between unique key and primary key?
Answer.  primary key can create cluster index on it. while on unique key we can create non cluster index.
unique key can have null value
primary key is only one in table while unique key can be many.
Question 7. how many nulls unique key can have?
Answer. only one
Question 8. can we define unique key on combination of keys?
Answer. yes

Max Bupa .NET - C# - Oracle Interview Questions Round 1



One of my friend gone through the max bupa technical interview for .net requirement for software engineer post.
here is some questions from the same interview.
Question. Tell me something about you ?
Answer.
Question. rate your self in C# and oracle ?
Answer. C# –8 Oracle - 8
Question. Define a constant at package level in oracle

Answer.  temp constant number := 12;
Question. how will you access this?
Answer. by using the variable name.
Question. will this constant have same values for same transaction?
Answer. yes
Question. How will you implement transaction in C# ?
Answer. begin trans, end trans
Question. Suppose you have these lines of code:
begintrans
oracle statement 1

committrans;

oracle statement 2

committrans;

oraclestatement 3

comittrans; // error

end trans
exception

rollback trans

now in rollbacktrans which whole transaction will rollback or just last committed trans. ?
Answer.  the transaction will rollback till oracle statement 2

Question. what is cluster index, what is not cluster index ?
Answer. cluster index created on primary key while non cluster index is created on non primary key and it is logical index.
Question. how will you define the cluster index ?
Answer. create clusterindex on table(column1, column2)
Question. when you create a table with primary key a cluster index already created. so what is use of this command?
Answer. suppose while defining table there is no primary key in that case we can use this command.
Question. how to define function in oracle and call ?
Answer.  check it by your self.
Question. what is difference between function and procedure?
Answer. 

1. function returns one value while procedure can return multiple.

2. function can be used with select statement while procedure can not.

3. there is some operation we can not do with functions

Question. suppose a table student have following details
id marks1 marks2
write a query to display id and grade of student as follows

1. when sum of marks1 and marks2 is greater than 60 display grade A

2. when sum of marks1 and marks2 is less than 60 and greater than 40 display grade B

3. when sum of marks1 and marks2 is less than 40 display grade C
Answer.
select case when marks1 + marks2 > 60 then
‘A’
when marks1 + marks2 > 40 then
‘B’
else
‘C’
end
from student ;

Question. What are the event datagird supports and how will you access the values of cell.
Answer. Check msdn.
Question. How to change the color of rows in datagrid?
Answer. use initialise row event
Question. how define a connection and open in oracle ?
Answer. check msdn.
Question. how to use pooling

Answer define pooling=true  in connection string
Question. how do you know that connection is already open and it have to pick from pool?
Answer. system detect automatically.
Question. write how to pass the parameters in oracle procedure.
Answer.
oda.SelectCommand = ocmd; 
oda.SelectCommand.Parameters.Add("my_column",   Oracle.DataAccess.Client.OracleDbType.Int32,15).Value=2;

RBS Selection Process - Technical Interview


One of my friend gone through the RBS selection process. He qualified  all the rounds and Joined the RBS Gurgaon.
Let me guide you step by step selection process of RBS. Please note that this process can differ at different centers and also for different positions.
These rounds were taken for the Software Developer/Designer and the technology was C# and SQL Server.
Round 1: RBS Online Test Round
This first round of RBS Selection process and you need to give this round at any nearby reliance  center or RBS Center.
This will be around 2 hour test of C# and SQL Server. Total number of questions will be around 56. These questions will contains multiple choice questions and maximum 3 options can be true.
This is IKM test and every question have different marks.
http://www.ikmnet.com/
Round 2: RBS Telephonic Interview Round
This is second round of RBS Selection process and In this interview they can ask basic questions of C# and SQL server like:
What is satellite assembly
how will you create strong name
They can give any problem and ask for solution in C#
Round 3: RBS Written test
This round can have some problems and you need to write a algorithms/Diagram codes / C# codes for these problems.
Round 4: RBS Technical Interview
This round is pure technical round and they can ask design patterns , implementations , real time problems solving of C# and SQL Server like
design a chess program using design pattern
Same kind of multiple rounds can be there until they are not satisfied with you.
So get ready for a challenging interview and clear your concepts.
Best of luck.

C# Written Test Questions 2010


One of my friend gone through the written test of a small company in Gurgaon. I decided to post some of questions from the test, so that the fresher's as well as experience holder get benefits. These are common questions and one need to know when going for interview.
This written test was for senior software engineer purely contains .net and C# questions.
Question 1: What is OOPs?
Answer: Object oriented programming like C#.
Question 2: What is XPath?
Answer: XPath is used to navigate through the elements and attributed in XML document.
Question 3: What is Strong type and Week type?
Answer: week type language support the any type variable declaration like java script supports var (no specific data type). Strong type language do not support var like C#.
Question 4: What is polymorphism?
Answer: Polymorphism means different forms, two types of polymorphism
1. runtime polymorphism
2. static polymorphism
Question 5: Difference between interface and abstract class?
Answer: Interface can have only function prototype and all functions should be implemented in inherited class. while abstract class can have function implementation.
Question 6: What is WCF, WPF, WWF? 
Answer: WCF: windows communication foundation
WPF: Windows presentation foundation
WWF: Windows workflow foundation
Question 7: What is Address, Contract and binding?
Answer: Address: An address that indicates where the endpoint can be found.
Contract: A contract that identifies the operations available.
Binding: A binding that specifies how a client can communicate with the endpoint.
Question 8: What is root class of .NET?
Answer: System.Object
Question 9: What is multicast delegate?
Answer: Multicast delegate is a delegate which allow to execute more than one method in single event.
Question 10: Can web services supports method overloading Explain with and example?
Answer: Yes, its same as simple method overloading just add a [web method] before the methods.
Question 11: What is difference between web services and WCF?
Answer: WCF = Web services + .NET Remoting
Question 12: Difference between View State and Session state?
Answer: View State is a client side storage management and store data while page postback. Session state is server side management and keep user specific data for session.
Question 13: What is machine.config?
Answer:  machine.config file apply settings to all applications running on the same machine.

Crystal Reports in .NET Video

0 comments

Crystal Reports in .NET Video

0 comments
http://www.youtube.com/watch?v=xgmNF1uBVm8