Friday, March 27, 2009

Is it possible to host Tcp endpoint wcf service in IIS?

IIS 5.1 and IIS 6 can only host HTTP bindings. IIS7 has WAS (Windows Activation Service) which allows hosting of endpoints bound to any transport protocol... so it would be capable of TCP.
If you must host with IIS 6, then you're stuck with the HTTP bindings. If not, consider self-hosting in a Windows Service.

Wednesday, March 25, 2009

what is the difference between pure and virtual pure function C#?

When a function is virtual it can have a function body. If you want to overload that function you can, but you don't have to, which is probably what you want in most cases of inheritance.

Pure virtual functions have no body and MUST be overloaded. You cannot create an instance of a class with a pure virtual function, so something else has to inherit from it and overload all pure virtual functions. This is generally what is done for Interface Inheritance, where the interface class is just a bunch of pure virtual functions and all the actual code is in classes that inherit it.

what is pure virtual function in C#?

When you define only function prototype in a base class without and do the complete implementation in derived class. This base class is called abstract class and client won’t able to instantiate an object using this base class.
A pure virtual function is a function that must be overridden in a derived class and need not be defined.
A virtual function is declared to be "pure" using the curious "=0"
syntax:
class Base
{
public: void f1(); // not virtual
virtual void f2(); // virtual, not pure
virtual void f3() = 0; // pure virtual
};

Advantage of "using" keyword C#

if u declare any managed/un-managed object in using block,
u don't need to explicitely dispose those object.. once the block execution is over, the Dispose will be called automatically.

using (SqlConnection cn = new SqlConnection(connectionString))
{// do something}

is the same as:

SqlConnection cn = new SqlConnection(connectionString)
try
{// do something...}
finally
{cn.Dispose();}
The using statement calls the Dispose method on the object in the correct way, and (when you use it as shown earlier) it also causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the object is read-only and cannot be modified or reassigned.
The using statement ensures that Dispose is called even if an exception occurs while you are calling methods on the object. You can achieve the same result by putting the object inside a try block and then calling Dispose in a finally block;

Tuesday, March 24, 2009

difference between aspnet_wp.exe and w3wp.exe?

The way an ASP.NET request is handled by IIS is quite different in IIS 6.0 when compared with 5.0. In 5.0, the ASP.NET worker process is handed off control by the aspnet_isapi extension in IIS. The aspnet_isapi dll runs in the inetinfo.exe process in IIS and functions what is known as the CLR host (a CLR host is the piece of unmanaged code which is responsible for loading the CLR into the memory). So aspnet_isapi “hands over” the processing to the worker process named aspnet_wp.exe, where the request passes through a series of HttpModules and an HttpHandler.

But in IIS 6.0, there is a driver named http.sys which listens to all the incoming requests (aspnet_isapi.dll is not in the picture at this point). The moment an ASP.NET specific request comes in, this driver starts an IIS 6.0 worker process (which is not related to ASP.NET at all) named w3wp.exe. This process now loads the aspnet_isapi.dll (CLR host) and the request follows through a similar sequence of HttpModules and HttpHandlers.

Tuesday, March 17, 2009

Threading C#

The .NET Framework defines two types of threads:
foreground and background.

By default when you create a thread, it is a foreground thread, but you can change it to a background thread.
The only difference between a foreground and background thread is that a background thread will be automatically terminated when all foreground threads in its process have stopped.

Thread Methods:
Suspend() -> Suspends the execution of a thread till Resume() is called on that.
Resume() -> Resumes a suspended thread. Can throw exceptions for bad state of the thread.
Sleep() -> A thread can suspend itself by calling Sleep(). Takes parameter in form of milliseconds. We can use a special timeout 0 to terminate the current time slice and give other thread a chance to use CPU time
Join()-> Called on a thread makes other threads wait for it till it finishes its task. States of a Thread.

States of a Thread:
States of a thread can be checked using ThreadState enumerated property of the Thread object which contains a different value for different states.
Aborted -> Aborted already.
AbortRequested -> Responding to an Abort() request.
Background -> Running in background. Same as IsBackground property.
Running -> Running after another thread has called the start()
Stopped -> After finishing run() or Abort() stopped it.
Suspended -> Suspended after Suspend() is called. Unstarted -> Created but start() has not been called.
WaitSleepJoin -> Sleep()/Wait() on itself and join() on another thread. If a thread Thread1 calls sleep() on itself and calls join() on the thread Thread2 then it enters WaitSleepJoin state. The thread exists in this state till the timeout expires or another thread invokes Interrupt() on it.

Properties of a Thread:
Thread.CurrentThread -> Static method gives the reference of the thread object which is executing the current code.
Name -> Read/Write Property used to get and set the name of a thread
ThreadState -> Property used to check the state of a thread.
Priority -> Property used to check for the priority level of a thread.
IsAlive -> Returns a Boolean value stating whether the thread is alive or not.
IsBackground -> Returns a Boolean value stating the running in background or foreground.


ThreadPriority levels: of thread is set or checked by using an enumeration i.e. ThreadPriority. The valid values are for this enumeration are;
Highest AboveNormal Normal BelowNormal Lowest

Synchronization in Threads:-
Using the Lock Keyword
Converting the Code to Enable Synchronization using the Lock Keyword

public void PrintNumbers()
{
lock (this)
{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(100);
Console.Write(i + ",");
}
Console.WriteLine();
}
}

-Using the Monitor Type
The C# lock keyword is just a notation for using System.Threading.Monitor class type. The lock scope actually resolves to the Monitor class after being processed by the C# compiler.
Converting the Code to Enable Synchronization using the Monitor Class

public void PrintNumbers()
{
Monitor.Enter(this);
try
{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(100);
Console.Write(i + ",");
}
Console.WriteLine();
}
finally
{
Monitor.Exit(this);
}
}

Ref : http://www.codeproject.com/KB/threads/thread_synchronization.aspx

C# language's Preprocessor directives?

The C# language's preprocessor directives are as follows:
�#if
�#else
�#elif
�#endif
�#define
�#undef
�#warning
�#error
�#line
�#region
�#endregion

Main use of directives are:
1.Conditional compilation. Using special preprocessing directives, you can include or exclude parts of the program according to various conditions.

2.Line control. If you use a program to combine or rearrange source files into an intermediate file, which is then compiled, you can use line control to inform the compiler of where each source line originally came from.

3.Error and Warning reporting. The directive `#error' causes the preprocessor to report a fatal error and the directive `#warning' is like the directive `#error', but causes the preprocessor to issue a warning and continue preprocessing.
Ref : http://www.csharphelp.com/archives/archive36.html

What are types of temp tables?

local and global.
Local temporary tables are created using a single pound (#) sign and are visible to a single connection and automatically dropped when that connection ends.
Global temporary tables are created using a double pound (##) sign and are visible across multiple connections and users and are automatically dropped when all SQL sessions stop referencing the global temporary table.

Temporary tables Vs Table variables

Temporary Tables vs. Table Variables
temporary tables: create table #T (…)And
table variables: declare @T table (…)

first difference is that transaction logs are not recorded for the table variables. Hence, they are out of scope of the transaction mechanism, as is clearly visible from this example:
create table #T (s varchar(128))
declare @T table (s varchar(128))
insert into #T select 'old value #'
insert into @T select 'old value @'
begin transaction
update #T set s='new value #'
update @T set s='new value @'
rollback transaction
select * from #T
select * from @T

s --------------- old value #
s --------------- new value @==================================================

properties and indexers in C#?

what are properties and indexers in C#?
Properties are known as smart fields and enable access to the fields of a class. Indexers are also called smart arrays in C# and can be used to use an object as an array. Properties are accessed by names but indexers are accessed using indexes.

Properties can be static but we cannot have static indexers. Indexers should always be instance members of the class. The get accessor of a property does not accept any parameter but the same of the indexer accepts the same formal parameters as the indexer. The set accessor of a property contains an implicit parameter called "value".The set accessor of an indexer contains the same formal parameters as that of the indexer and also the "value" as an implicit parameter.

debug an ASP.NET Web application?

How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.

Debugging Tools

What are the debugging tools come with the .NET SDK?
CorDBG – command-line debugger, and
DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.

Tuesday, March 3, 2009

what is x:Code in XAML?

x:Code is a directive element defined in XAML. An x:Code directive element can contain inline programming code. The code that is defined inline can interact with the XAML on the same page. The following example illustrates inline C# code. Notice that the code is inside the x:Code element and that the code must be surrounded by to escape the contents for XML, so that an XAML processor (interpreting either the XAML schema or the WPF schema) will not try to interpret the contents literally as XML.


[XAML]


xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

x:Class="MyNamespace.MyCanvasCodeInline"
>

<Button Name="button1" Click="Clicked" > Click Me! </Button >


void Clicked(object sender, RoutedEventArgs e)

{

button1.Content = "Hello World";

}

]]>


State management in ASP.NET

ASP.NET offers a number of places to store state, both on the client and server.

Application - Stored on the server and shared for all users. Does not expire. Deprecated by Cache (below).
Cache - Stored on the server and shared for all users. Can expire.
Session - Stored on the server. Unique for each user. Can expire.
ViewState - Stored in a hidden page input (by default). Does not expire.
Cookies - Stored at the client. Can expire. QueryString - Passed in the URL. Must be maintained with each request.
Context.Items - Only lasts for one request's lifetime. More.
Profile - Stores the data in the database. Can be used to retain user data over multiple request and session.

Improve Performance in ASP.NET

The following are the important tips to improve ASP.NET website. (Thanks to wiki.asp.net).

1) Set debug=false under compilation as follows:

2) Use Server.Transfer instead of Response.Redirect.

3) Always check Page.IsValid when using Validator Controls

4) Use Foreach loop instead of For loop for String Iteration.

5) Use Client-Side Validation.

6) Check “Page.IsPostBack”. To avoid repetition code execution.

7) GIF and PNG are similar, but PNG typically produces a lower file size.

8) Use the AppOffline.htm when updating binaries

9) Turn off Tracing unless until required.

trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/


10) Precompiled pages and disable AutoEventWireup; setting the AutoEventWireup attribute to false in the Machine.config file.

11) Turn off Session State, if not required.
sessionstate timeout="20" cookieless="false" mode="Off" stateconnectionstring="tcpip=127.0.0.1:42424" sqlconnectionstring="data source=127.0.0.1;Trusted_Connection=no"


12) Select the Release mode before making the final Build for your application.

This option is available in the Top Frame just under the Window Menu option. By default, the Mode is Debug

13) Disable ViewState when not required.

EnableViewState="false"

14) Avoid frequent round trips to the Database.

15) Use Caching to improve the performance of your application.

16) Validate all Input received from the Users.

17) Use Finally Method to kill resources.

18) The String and Stringbuilder Magic.

It is nice to use Stringbuilder instead of String when string are Amended. Strings occupy different memory location in every time of amended where stringbuilder use single memory location

19) Never use object value directly; first get object value in local variable and then use. It takes more time then variable reading.

20) Avoid Exceptions: Use If condition (if it is check proper condition)

21) Code optimization: Avoid using code like x = x +1; it is always better to use x+=1.

22) Data Access Techniques: DataReaders provide a fast and efficient method of data retrieval. DataReader is much faster than DataSets as far as performance is concerned

23) Before doing a bulky ASP code processing, you can check to make sure Response.IsClientConnected.

24) As always, avoid session variables because each ASP page runs in a different thread and session calls will be serialized one by one. So, this will slow down the application. Instead of session variables you can use the QueryString collection or hidden variables in the form which holds the values.

25) Enabling buffering will improve the performance, like
response.buffer=true

Then use:
response.flush=true

26) Use Repeater control instead of DataGrid , DataList, Because It is efficient, customizable, and programmable.

27) Data listing is more time consume when large data are retrieve from database.

Paging will display only particular data but take load of all data.

Fetch only data that is needed for current page.

28) Avoid Inline JavaScript and CSS

29) Use single css file instead of multiple css file.

Try your best to combine all your CSS based classes into a single .css file as lot of .css files will cause a large amount of requests, regardless of the file sizes.

.css files are normally cached by browsers, so a single and heavy .css file doesn’t cause a long wait on each page request.

Inline .css classes could make HTML heavy, so again: go ahead with a single.css file.

30) Reduce cookie size

31) Compress CSS, JavaScript and Images

Online compressors are available; to compress file please refers following web and Replace your file content with optimize code.

http://iceyboard.no-ip.org/projects/css_compressor for CSS compression

www.xtreeme.com/javascript-optimizer/ . For JS Compression

32 .Use Cache appropriately

i. Page output caching:
@ OutputCache Duration="3600" VaryByParam="none"

ii. Page fragment caching:

Write a Page output caching code into each User Control

iii. Data caching:



33) Use server side compression software such as Port80s http://www.port80software.com/products/httpzip/

Monday, March 2, 2009

Design Pattern

What are the folders for MVC patterns(ASP.NET project)?

Content: this folder is meant to include all the styles and images for the UI of the web application.
Controllers: this folder will contain all the classes for the controllers.
Models: the classes for the model will be located in this folder. In a simple ASP.NET application they could be a DataSet, a LINQ model or, in a more complex application, this could contain a wrapper to the Business Logic which could live in a separate assembly.
Views: separated in one folder per controller, here are all the Views (the aspx pages) that will be rendered back to the user.
Views\Shared: this last "standard" folder contains anything that pertains to the Views, but not specific to just one View (for example, Master Pages, shared controls and so on).

Wednesday, February 11, 2009

SQL Server Reporting Services (SSRS)

2.Can you explain Report definition language (RDL) file in reporting services?

-RDL is an XML description of a report in reporting services. So basically the RDL file has the XML grammar which describes a reporting services report

3. what are the basic process of making a report in reporting services?

Here are the basic steps which will help you in creating reports in reporting services:-
. Open Visual studio 2005
à File à New project
à Select 'Business Intelligence Reports'
à Select Report Server project..
When the project is created in the solution explorer you will see two folder 'Shared data resources' ( we will come to data sources in the coming questions) and 'Reports'. Right click the 'Reports' folder and click add new reports.. You need to give credentials in the wizard. Once done it pops up a query builder. Specify the report query in the query builder and go next.. Wizard then helps you to select the report type and some other features. Next , next and you should see a RDL file in your 'Reports' folder. . Click on the view menu and select tool box and you should be able to design the report.. Till now we are only in the design mode of report. As said previously all reports meta-data are stored in SQL Server database 'ReportServer'. In order that the report's meta-data gets saved in database we need to publish the report.. To publish the report we need to specify the IIS report path. So right click on the report project, select properties and specify the 'TargetServerURL' property.


4. How can we consume the reports in ASP.NET?

There are three famous ways of calling reporting services report in ASP.NET:-
. Using URL way to access reports..
Using reporting web service to programmatically access reports..
Using report viewer control.

5.Can you explain the difference between private and shared data sources?

Private data source is used by single report only while shared data sources are shared between reports. As a practice it is good to have shared data source so if you want to change anything you need to change only on one data source.
6.How does reports caching in reporting services work ?

reporting services has two main databases 'ReportServer' and 'ReportServerTempDB'

SQL Server Reporting Services (SSRS)

1,In IIS we have two applications 'Reports' and 'Reportserver', what do they do?

While installing reporting services there are two virtual directories created Reports and Reportserver.-The 'Reports' virtual directory is like an admin. If you browse to http://yourpcname/reports/home.aspx page you can view, edit properties and display reports-The second virtual directory is the 'ReportServer' this helps us to use browse reports and use the same in ASP.NET code using URL methodology , try browsing to http://yourpcname/reportserver/ you can easily figure out what this virtual directory is all about