Wednesday, August 15, 2007

DotnetFAQ1

Framework

Dot net framework is a platform contains collection of services in distributed manner. Using this we can design, develop, build and run the applications.

The services are 1) Runtime 2) Language compiler and 3) Base class libraries.

1) Runtime

The Common Language Runtime
At the heart of the .NET Framework is the Common Language Runtime (CLR). The CLR performs Type safety checking, application memory isolation, memory management, garbage collection, and cross language exception handling.

The CLR greatly simplifies cross language communication through the Introduction of the Common Type System (CTS). The CTS defines all of the basic types that can be used in the .NET Framework and the operations that can be performed on those types. All CTS types are classes that derive from a base class called System. Object
A subsection of the CTS called the Common Language Specification (CLS) specify how .NET languages share and extend one another’s libraries.

The CLR another responsibility is security. An integral part of the .NET Runtime is something called Code Access Security. You can modify the permissions that are granted to code from a certain location using a utility called CASPOL.EXE.

The .NET Runtime classes are organized in hierarchical manner using namespaces.

. Net Framework is a SERVICE as well as Development platform.

When CLR compiles the managed code this can be converted into MSIL code.

Base class Libraries

Common libraries for all the .net languages.

64 base class libraries are there.
System.dll Basic
System.io.dll File Handling
System.data.dll Ado.net
System.web.dll Asp.net

These libraries developed using c# language.



Assemblies

Assemblies are the building blocks of the Dot net Framework.
Assembly can be defined as collection of user defined types or resources.
An assembly consists of one or more files like Dll, exe and html files.
Assembly consists of 3 things.
1) Manifest 2) Type Metadata and 3) MSIL code.

Manifest: Manifest will describe the assembly; this will describe information about other assemblies. We can view manifest through ILDASM.EXE tool.

Type Metadata: Description of namespaces and us er defined types.

MSIL code: .Net CLR understandable code is called as MSIL, Microsoft Intermediate Language.

Assemblies are two types. 1) Shared assemble and 2) private assembly.

Shared Assemble::(name, key and version)
When the assembly is required in more than one application through out the system, we use shared assembly or machine wide assembly.
When the assembly is signed with public key then it is called as Strong named assembly.
Then this Strong name assembly is placed in GAC, and then it is called Shared.

Public key takes 8bytes memory.
Version number has 4 parts. Major.Minor.Build.Revision
Revision: When we are modifying logic of the subprogram then change.
Build: When u adds a new subprogram.
Minor: When u change subprogram Name and class Names.
Major: When u change subprogram Name, Class Names and new classes

Exe and Dll

You can create an object of Dll but not of the EXE.
Dll is an In-Process Component whereas EXE is an Out-Process Component.
Exe is for single use whereas you can use Dll for multiple uses.
Exe can be started as standalone where Dll cannot be.

Namespaces

Namespaces provide a scope (or container) in which types are defined.
A Namespace can be defined as logical container for collection of user-defined types like class, interface.
Namespaces can also be nested. You will use namespaces throughout the .NET framework to:
• Access the .NET Runtime classes
• Access custom classes authored by other developers
• Provide a namespace for your own classes, to avoid naming conflicts with other classes and namespaces

Reflection

System. Reflection is the namespace.

All Dot net assemblies have metadata information stored about the types defined in modules. This metadata information can be accessed by mechanism called as Reflection.
Using reflection we can dynamically find the methods information.

Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember), or even dynamically create types at run-time (see System.Reflection.Emit.TypeBuilder).

Attribute


Attaching metadata is called as attribute. We can view attributes through the ildasm tool.

Intrinsic and custom are two methods.
Intrinsic are supplied with the framework.

Vb.net and C#. Net

Advantages of VB.Net:

It supports optional parameters and Com Interoperability.
With option Strict Off late binding is supported.
Has WITH Constructs.

C#. NET advantages:

XML document is generated from source code.
Operator overloading is supported.
Using statement for disposing unmanaged references.
Access to unsafe code (i.e. pointers)




Accessspecifiers

Public
Can be instantiated by any element of the application.
Visible to any method of any class.
Friend (internal)
Can be instantiated only by members of the same assembly.
Private
Can be accessible only to the methods of same class.
Protected
Can be accessible by the methods in the same class and the methods that are derived from the same class.
Protected internal
The methods in the same class, the methods derived from the class and the assemble where the class is located.

Static

Array:____Binarysearch(),copy(),indexof(),sort(),reverse(),syncronized()

Array list-----adapter (), fixed size (), repeat(), Sysncronized()

String:----compare(),concat(),copy(),equals()

Appdomain::-------------createdomain(),getcurrentthreadid()



They can't be instantiated.
By default object is created on the first method call to that object.
Static classes cannot be inherited.
Static classes can have only static members
Static classes can have only static constructors.


Structure

Collection of dissimilar data with related functionalities is called structure.

Structure comes under value type.
Doesn’t support inheritance.
Doesn’t support destructor.
Structures don’t use Garbage collector like classes.
Structure also has constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
Structures also implement interfaces.
Structures also have without and with parameter constructors.
Structures also have delegates and events.



Overloading

A sub program more than one signature is called as method overloading.

Shadowing (NEW)

Overriding redefines only the implementation, while shadowing redefines the whole element.
In overriding derived classes can refer the parent class element by using "ME" keyword, but in shadowing u can access it by "MYBASE"

Interface

Interface defines the behavior of the class.

An interface can't implement another interface.
An interface can inherit another interface.
A class can inherit another class by implementing more than one interface.

In interfaces all the methods are abstract, i.e. without implementation.
The variables are Static final only.
An interface implementation may be added to any existing third party class.
You can write a new code for an interface.
Speed of interface is slow.

I unknown interface:

Every COM object supports at least one interface, i.e. I Unknown interface.
This interface has 3 methods.
1) AddRef: Increment count by one.
2) Release: Decrement Count by one.
3) Query Interface.


When count is Zero then object will be freed from the memory.



Ado.net
Namespace: System. Data: This contains Dataset, Data table, and Data Relation objects.
System.data.sqlclient: this contains sqlconnections, sqlcommand, and data reader.

DATASET
The Dataset can be defined as In-memory database for the client application. The Dataset object contains a collection of zero or more Data Tables, Dataset is purely disconnected architecture. The Dataset contains Data Relations collection, DataTable collection, Data Rows collection, Data Columns collection, and the Constraint collection,

DATAREADER
The Data Reader object provides a forward-only, read-only, connected record set.
When data reader is used we must close the connection. If we use command behavior connection will be implicitly called. We didn’t close the connection.

DATAADAPTER
The Data Adapter object populates a disconnected Dataset or Data Table with data and performs updates. The Data Adapter is mediator between the database and a Dataset. The Data Adapter fills a Data Table or Dataset with data from the database whenever the Fill method is called. The Data Adapter provides four properties

Command
Command objects provide three methods that are used
!) ExecuteNonQuery: Executes commands that return no records, such as INSERT, UPDATE, or DELETE. It returns how many records are affected by the query.
2) Execute Scalar. Returns a single value from a database query
3) Execute Reader. Returns a result set by way of a Data Reader object execute commands on the database:
Connection
Oledbconnection object is used with an oledb provider
Sqlconnection object uses with an sqlserver database

Ado.net Architecture

The most important section in Ado.net architecture is “Data Provider”. Data provider provides access to data source. This handles like, opening and closing connection, retrieve data and update data. The main sections of data provider are:
Connection-Establish connection
Command object-To use stored procedures
Data Adapter – This is bridge between data store and dataset
Data Reader – This reads data from data source in forward only.

Dataset object represents disconnected and cached data. The dataset is not directly connected to the database rather it connects to Data Adapter, who is responsible for filling the dataset. Dataset can have one or more Data Tables and relations.
Data View object is used to sort and filter data in Data Table.

Dif between dataset and data Reader

Data Reader provides forward-only and read-only access to data,
Data Set object can hold more than one table with the relationships between them.
Data Reader is connected architecture, where as Data Set is Disconnected.



Garbage Collection

Garbage collector is the service of the CLR.
The garbage collector is a Low priority thread that runs in the background of managed .NET applications. It constantly traces and finds the non-referenced objects and freed them. This will release the objects from the heap memory, which doesn’t have reference from the stack. This will call by the clr implicitly.

Whenever user wants, then he calls the GC explicitly by SupressFinalize () method.

Exception Handling

Exception: The runtime error, which can be handled by the developer, is called as exception.

Try
Catch
Finally
Try: Will contain collection of statements, which can cause the error.
Catch: Will contain the solution for the error.
Finally: A try block can have any number of catch blocks but only one finally block.

There are two types of exceptions: exceptions generated by an executing program and exceptions generated by the common language runtime. System. Exception is the base class for all exceptions in C#. Several exception classes inherit from this class including Application Exception and System Exception. System. Exception includes IoException, Web Exception etc.
The common language runtime throws System Exception.
A user program rather than the runtime throws the ApplicationException. The System Exception includes the ExecutionEngineException, StackOverFlowException etc. It is not recommended that we catch System Exceptions.

Ex:
System.outofmemoryexception
System.nullreferenceexception
System.invalidcastexception
System.indexoutofrangeexception
System.arraytypemismatchexception
System.arithmeticexception
System.devidebyzeroexceptin
System.overflowexception

Threading

Unit of code by maintaining its own execution path is called as Thread. When the application has only one execution path then it is called as single threaded application. When the application has more than one execution path then it is called as multithreaded application.
Thread has the methods,
Start, Suspend, Resume, Sleep and Join.
Priority in the Threads.

ThreadPriority.Highest, AboveNormal, Normal, BelowNormal and Lowest.

sleep-suspent
interrupt-resume

Thread. Join:

Suppose t1 and t2 are two threads, while executing t1 you call t2.join (), so t1 will wait until t2 has completed its execution, and again invoke t1.

We use events with the threading.

Monitor: A block of code runs without being interrupted by code running on other threads.

Difference between Thread and Process:

Thread is a path of execution that runs on CPU,
Process is a collection of threads that share the same virtual memory.
Process has at least one thread, and a thread is always runs under a process.

Delegate

Delegate means function pointer. It represents the address of the method or subprogram. It allows you to pass a reference to the entry point for a method and invoke that method without making an explicit method call. When you declare a delegate, you specify the signature of the method that it can call and the return type. A delegate represents how events work.

Events:

Declaring events is directly tied to delegates. Events in Visual C# are raised by calling them by name as you would a method.
To handle an event in Visual C#;
Create an instance of the appropriate delegate for the event that specified the method that will handle the event, and use the += operator to associate the event with the delegate.

Collection

Collections provide advanced functionality for managing groups of objects. Collections can be resized dynamically, and members can be added and removed at run time.
The System.Collections.ArrayList class provides general collection functionality suitable for most purposes. This class allows you to dynamically add and remove items from a simple list. Accessing the item index retrieves items in the list. The list of objects managed by the Array List is a zero-based collection. Zero-based means that the first object added to the list is assigned the index zero and every subsequent object to be added is assigned to the next available index.

Indexer

In Visual C#, the indexer is the equivalent of a Visual Basic .NET default property. The indexer is a specialized property that allows you to expose a group of objects on the name of the object. The name used in the indexer code is always this, which indicates that the name of the object itself will be used to access the property.
Public int this ()
{
get
{
return IntArray[index];
}
set
{
IntArray[index] = value;
}
}

Representing group of objects like an array is called as indexer.
In C# we didn’t have any static Indexers.

Array List

Array list is an array whose size can automatically increase and decrease dynamically.
Array list can hold item of different types. You can access any item in array using the index value of the array position.

Value and Reference

Value types directly contain their data. They are stored in stack.

Reference types store a reference to the values memory address, and are located on Heap.

Reference types are self-discribing. Like pointer and interface.

Variables of value types, operations on one variable do not affect other variable.
Variables of reference types, operations on one variable can affect the other variable.

Boxing and Unboxing

Boxing, converting value type into reference type (object).

This is implicitly done by the clr.
int x;
object y;
x=10;
y=x

Unboxing, converting reference type into value type.
This is explicitly handled.
x=(object)y
Com and Dcom

COM is a technology for component software development. Which is language independent.
DCOM is Distributed version of COM. It differs from COM,
Com Interoperability

We can use COM Components in .NET through the RCW (Runtime callable wrappers).
Dot net components communicate with COM is possible through RCW. In this we can use TLbimp.exe tool (Type Library Import tool)
System.Runtime.Interopservices namespace is used.

In this Com classes and interface methods are converted into Metadata.

Dot net Components are used in Com With CCW (Com Callable Wrapper)
In this we use a tool, Tlbexp (Type library export tool)

Object Pooling

Object pooling is a COM+ service that enables you to reduce the overhead of creating each object from scratch. When an object is activated, it is pulled from the pool. When the object is deactivated, it is placed back into the pool to await the next request. You can configure object pooling by applying the ObjectPoolingAttribute attribute to a class that derives from the System.EnterpriseServices.ServicedComponent class.

When object is activated it is activated from the pool.
When object is deactivated it is pushed back in to the pool.

When a class is marked with object pooling attribute it cannot be inherited.
Object pooling lets you control the number of connections you use

Application Domain

In Application Domains multiple application can run in same process with out influencing each other. If one of the application domains throws error it does not affect the other application domains.

Remoting

Dcom replacement is Remoting.
Use Remoting for more efficient exchange of information when you control both ends of the application. Remoting is designed to .Net to .Net Communication.

Remoting object calls different Application Domains. Remote objects run in different process client calling the remote object can't call it directly. So they use proxy.

Namespace: System.MarshllbyRefObject.

Remoting depends on
1) Channels
Tcp (transaction commit protocol), data representation.
Http(hypertext transperprotocol) xmlbased syntax
2) Serialization & Desertification
Coverting object into stream Serialization
Reading the stream and construction object is Deserialization.
3) Formatter classes
Binary formatter: it is used by tcp channel
Soap formatter: it is used by http channel

Namespace: System.Runtime.Serialization.Formatters.Binay/soap

Serialize (object, stream)
DeSerialize(Stream)
4) Activation modes
Client activated and server activated.

Server activated: when user makes a call to the method of class, the object creation takes place.
Client activated: whenever the client request comes to the remote server an object will be created and the reference will be send to client application.

Client activated objects maintain state.

Marshal by value: when the client request comes, object will be created on the server machine. This object will be send to client machine.

Marshal by Reference: when the client request comes, object will be created on the server machine. This object reference will be send to client machine.

Single call: When user makes a call to the method, the object will be created, after sending the response the object will be destroy. This is stateless.
For single client we have single object.

Singleton: This will maintain single object for all the clients at a time. The lifetime will be 5 min by default.

Client can be created objects on the server by two ways, one is using Keyword "NEW" and second one is "Activator.CreateInstace ().

Web service

Communication between different business partners is possible by using web services.
Way of invoking a remote method over http connection soap.
Remote procedure call is based on soap protocol.
Description will be generated using wsdl, which is xml format.
Transmission is through xml based.
Transmission protocol is http.

Web services do not have any state. Web services can access Asp.Net intrinsic objects like session, application.
Web services are completely open standards.
To expose each method as a web service, u simply add [Web method] attribute before it.

WSDL: Is a language derived from xml syntax? Wsdl describes the methods names, parameters, location of the web service and standards for request and response.
To view the wsdl content type like http://localhost/WSCalculator/Service1.asmx? Wsdl

To Create the Proxy for the client
Wsdl http://localhost/WSCalculator/Service1.asmx? Wsdl

Togenerate proxy for the client application in the form of xmlfile is by soap.
soapsuds -ia:RemotingServer -oa:ClientProxy.dll
soapsuds -ia:RemotingServer -os:ClientProxy.xml

ia::: input Assembly
oa:: Output Assembly
os:: output stream

Proxy code will contain complete logic for interacting with web service for method calls.

Namespace:: System.Web.Services
if includes 1)webservice 2) webservice attribute class and 3) webmethod

The extension is asmx.

WebPages: Provide consumption of data, this will for end user.
Web service: Provide consumption of logic, this will for Developer.

When we want to reduce number of interactions between werbservice method and database server applying catching for the web method.

Web services supports only text based format.
ie, http-GET
http-Post
Soap

Http-Get and Http-Post supports basic data types only.
Soap supports complex data types like arrays and user-defined types.
Soap will define standards for exchanging data between client and web service interims of request and response.
It is not vendor specific; it is xml standard, introduced in 99-2000.

No comments: