June 22, 2011

WCF interview

What are the important principles of SOA (Service oriented Architecture)?
What are ends, contract, address, and bindings?
Which specifications does WCF follow?
What are the main components of WCF?
Explain how Ends, Contract, Address, and Bindings are done in WCF?
What is a service class?
What is a service contract, operation contract and Data Contract?
What are the various ways of hosting a WCF service?
How do we host a WCF service in IIS?
What are the advantages of hosting WCF Services in IIS as compared to self-hosting?
What are the major differences between services and Web services?
What is the difference WCF and Web services?
What are different bindings supported by WCF?
Which are the various programming approaches for WCF?
What is one-way operation?
Can you explain duplex contracts in WCF?
How can we host a service on two different protocols on a single server?
How can we use MSMQ bindings in WCF?
Can you explain transactions in WCF?
What different transaction isolation levels provided in WCF?
Can we do transactions using MSMQ?
Can we have two-way communications in MSMQ?
What are Volatile queues?
What are Dead letter queues?
What is a poison message?

May 16, 2011

Differences between user controls and custom controls

This question is asked in every interview happens for asp.net in all organizations, article will help the interviewee (candidate).

 FactorsUser controlCustom control
DeploymentDesigned for single-application scenarios


Deployed in the source form (.ascx) along with the source code of the application


If the same control needs to be used in more than one application, it introduces redundancy and maintenance problems
Designed so that it can be used by more than one application


Deployed either in the application's Bin directory or in the global assembly cache


Distributed easily and without problems associated with redundancy and maintenance
CreationCreation is similar to the way Web Forms pages are created; well-suited for rapid application development (RAD)Writing involves lots of code because there is no designer support
ContentA much better choice when you need static content within a fixed layout, for example, when you make headers and footersMore suited for when an application requires dynamic content to be displayed; can be reused across an application, for example, for a data bound table control with dynamic rows
DesignWriting doesn't require much application designing because they are authored at design time and mostly contain static dataWriting from scratch requires a good understanding of the control's life cycle and the order in which events execute, which is normally taken care of in user controls

April 25, 2011

Increase SQL Server performance

Following are tips which will increase your SQl performance :-
  1.  Every index increases the time takes to perform INSERTS, UPDATES and DELETES, so the number of indexes should not be too much. Try to use maximum 4-5 indexes on one table, not more. If you have read-only table, then the number of indexes may be increased.308
  2.  Keep your indexes as narrow as possible. This reduces the size of the index and reduces the number of reads required to read the index.
  3. Try to create indexes on columns that have integer values rather than character values.
  4. If you create a composite (multi-column) index, the order of the columns in the key are very important. Try to order the columns in the key as to enhance selectivity, with the most selective columns to the leftmost of the key.
  5. If you want to join several tables, try to create surrogate integer keys for this purpose and create indexes on their columns.
  6. Create surrogate integer primary key (identity for example) if your table will not have many insert operations.
  7. Clustered indexes are more preferable than nonclustered, if you need to select by a range of values or you need to sort results set with GROUP BY or ORDER BY.
  8. If your application will be performing the same query over and over on the same table, consider creating a covering index on the table.
  9. You can use the SQL Server Profiler Create Trace Wizard with "Identify Scans of Large Tables" trace to determine which tables in your database may need indexes. This trace will show which tables are being scanned by queries instead of using an index.

April 23, 2011

what is Static Constructors?

Static Constructors: A static constructor is used to initialize any static data, or to perform a particular action that needs performed once only. It is called automatically before the first instance is created or any static members are referenced.

Static constructors have the following properties:


1. A static constructor does not take access modifiers or have parameters.
2. A static constructor is called automatically to initialize the class before the first instance is created or any static members are referenced.
3. A static constructor cannot be called directly.
4. The user has no control on when the static constructor is executed in the program.
5. A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file.

Static constructors are also useful when creating wrapper classes for unmanaged code, when the constructor can call the LoadLibrary method.








April 13, 2011

Datatable Pivots with C# and ASP.NET

private DataTable PivotTable(DataTable origTable)
        {
          
                DataTable newTable = new DataTable();
                DataRow dr = null;
                //Add Columns to new Table
                for (int i = 0; i < origTable.Rows.Count; i++)
                    newTable.Columns.Add(origTable.Rows[i][0].ToString(), typeof(String));
                //Execute the Pivot Method
                for (int cols = 0; cols < origTable.Columns.Count; cols++)
                {
                    dr = newTable.NewRow();
                    for (int rows = 0; rows < origTable.Rows.Count; rows++)
                    {
                        if (rows < origTable.Rows.Count)
                        {
                            dr[0] = origTable.Columns[cols].ColumnName; // Add the Column Name in the first Column
                            dr[rows] = origTable.Rows[rows][cols];
                        }
                    }
                    newTable.Rows.Add(dr); //add the DataRow to the new Table rows collection
                }
                newTable.Rows[0].Delete();
                return newTable;
            }
          
        }

April 11, 2011

what is endpoint in wcf

All communication with a Windows Communication Foundation (WCF) service occurs through the endpoints of the service. Endpoints provide clients access to the functionality offered by a WCF service.
Each endpoint consists of four properties:
  • An address that indicates where the endpoint can be found.

  • A binding that specifies how a client can communicate with the endpoint.

  • A contract that identifies the operations available.

  • A set of behaviors that specify local implementation details of the endpoint.

This topic discusses this endpoint structure and explains how it is represented in the WCF object model.

The Structure of an Endpoint

Each endpoint consists of the following:
  • Address: The address uniquely identifies the endpoint and tells potential consumers of the service where it is located. It is represented in the WCF object model by the EndpointAddress class. An EndpointAddress class contains:

    • A Uri property, which represents the address of the service.

    • An Identity property, which represents the security identity of the service and a collection of optional message headers. The optional message headers are used to provide additional and more detailed addressing information to identify or interact with the endpoint.

    For more information, see Specifying an Endpoint Address.

  • Binding: The binding specifies how to communicate with the endpoint. This includes:

    • The transport protocol to use (for example, TCP or HTTP).

    • The encoding to use for the messages (for example, text or binary).

    • The necessary security requirements (for example, SSL or SOAP message security).

    For more information, see Windows Communication Foundation Bindings Overview. A binding is represented in the WCF object model by the abstract base class Binding. For most scenarios, users can use one of the system-provided bindings. For more information, see System-Provided Bindings.

  • Contracts: The contract outlines what functionality the endpoint exposes to the client. A contract specifies:

    • What operations can be called by a client.

    • The form of the message.

    • The type of input parameters or data required to call the operation.

    • What type of processing or response message the client can expect.

    For more information about defining a contract, see Designing Service Contracts.

  • Behaviors: You can use endpoint behaviors to customize the local behavior of the service endpoint. Endpoint behaviors achieve this by participating in the process of building a WCF runtime. An example of an endpoint behavior is the ListenUri property, which allows you to specify a different listening address than the SOAP or Web Services Description Language (WSDL) address. For more information, see ClientViaBehavior.

Go to question list 

Components of WCF

The main components of WCF are

1. Service class

2. Hosting environment
3. End point 


Go to question list 

Difference between web services and WCF

Windows Communication Foundation (WCF) has an ASP.NET compatibility mode option to enable WCF applications to be programmed and configured like ASP.NET Web services, and mimic their behavior.

Major Difference is That Web Services Use XmlSerializer But WCF Uses
DataContractSerializer which is better in Performance as Compared to XmlSerializer.
Key issues with XmlSerializer to serialize .NET types to XML

* Only Public fields or Properties of .NET types can be translated into XML.
* Only the classes which implement IEnumerable interface.
* Classes that implement the IDictionary interface, such as Hash table can not be serialized.

Important difference between DataContractSerializer and XMLSerializer.

* A practical benefit of the design of the DataContractSerializer is better performance over Xmlserializer.
* XML Serialization does not indicate the which fields or properties of the type are serialized into XML where as DataCotratSerializer Explicitly shows the which fields or properties are serialized into XML.
* The DataContractSerializer can translate the HashTable into XML.


Go to question list 

March 29, 2011

Capgemini Interview Questions WCF, Asp.net, C#.net, Sql server

Windows Communication Foundation (WCF) questions:
1. Difference between web services and WCF?
2. Components of WCF?
3. What is End Point?
4. WCF Hosting types?
5. How many protocols can be used to access WCF?
6. What is WCF Binding?
7. What is WCF contract?
8. What are the transfer modes available?
Oops questions:
1. Features of Oops?
2. What do you understand by polymorphism and message passing?
3. Difference between overloading and overwriting?
C#.net questions
1. What is the use of private constructor and why to make constructor as private?
2. How to erase unmanaged code objects from memory?
3. What is the use of finalize() method?
4. Why to use GC.Collect() method?
5. How many catch blocks can be created after try block?
6. Can we put try without catch?
7. What is delegate?
8. What are anonymous methods?
9. What will happen if I call 5 times a single anonymous method?
10. What is shared classes?
ASP.net questions
1. What is impersonation?
2. How many securities provided by asp.net?
3. What is assembly?
4. Difference between assembly and namespaces?
5. What is strong name?
6. What do you meant by late binding?
Sql Server
1. Tell me types of logs generated by sql server?
2. How to perform exception handling in sql server?
3. If I had a before update trigger and I am updating trigger and table in same time what will happen?
4. Single line statement for copy the structure of table to another table?

March 4, 2011

ASP.NET MVC

Model: The model contains the core information for an application. This includes the data and validation rules as well as data access and aggregation logic.
View: The view encapsulates the presentation of the application, and in ASP.NET this is typically the HTML markup.
Controller: The controller contains the control-flow logic. It interacts with the Model and Views to control the flow of information and execution of the application.
This separation of entity allows you to have nimbleness and flexibility in building and maintaining your application. For example, by separating the views, you can iterate on the appearance of your application without touching on any of the core business logic. You can also separate work by role, so that, for example designers can work on the views, while developers work on the model.
ASP.NET MVC brings the power of this development paradigm to ASP.NET development, allowing you to use your .NET development skills to build MVC applications.
It gives you
Complete control over your HTML Markup
Enables rich AJAX and jQuery integration
Allows you to create SEO-friendly URLs for your site
Makes Test Driven Development (TDD) easy

February 24, 2011

Value Converters

Introduction

If you want to databind two properties that have incompatible types, you need a piece of code in between, that converts the value from source to target type and back. This piece of code is called ValueConverter. A value converter is a class, that implements the simple interface IValueConverter with the two methods object Convert(object value) and object ConvertBack(object value).
How to implement a ValueConverter

WPF already provides a few value converts, but you will soon need to implement your own converts. To do this, add a class to your project and call it [SourceType]To[TargetType]Converter. This is a common naming for value converters. Make it public and implement the IValueConverter interface. That's all you need to do.


public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
// Do the conversion from bool to visibility
}

public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
// Do the conversion from visibility to bool
}
}



How to use a ValueConverter in XAML

First thing you need to do is to map the namespace of your converter to a XAML namespace. Then you can create an instance of a value converter in the resources of the view and give it a name. Then you can reference it by using {StaticResource}









Simplify the usage of ValueConvers

If you want to use a normal ValueConverter in XAML, you have to add an instance of it to the resources and reference it by using a key. This is cumbersome, because and the key is typically just the name of the converter.

A simple and cool trick is to derive value converters from MarkupExtension. This way you can create and use it in the binding like this: Text={Binding Time, Converter={x:MyConverter}}, and that is quite cool!


public abstract class BaseConverter : MarkupExtension
{
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}



StringFormat Converter

The StringFormatConverter is a useful converter to control the format of an implicit string conversion of an object (e.g. if you bind a DateTime to a TextBlock ).


[ValueConversion(typeof(object), typeof(string))]
public class StringFormatConverter : BaseConverter, IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
string format = parameter as string;
if (!string.IsNullOrEmpty(format))
{
return string.Format(culture, format, value);
}
else
{
return value.ToString();
}

public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return null;
}
}
http://www.wpftutorial.net/ValueConverters.html

Data Binding (WPF)

Windows Presentation Foundation (WPF) data binding provides a simple and consistent way for applications to present and interact with data. Elements can be bound to data from a variety of data sources in the form of common language runtime (CLR) objects and XML. ContentControls such as Button and ItemsControls such as ListBox and ListView have built-in functionality to enable flexible styling of single data items or collections of data items. Sort, filter, and group views can be generated on top of the data.

The data binding functionality in WPF has several advantages over traditional models, including a broad range of properties that inherently support data binding, flexible UI representation of data, and clean separation of business logic from UI.

This topic first discusses concepts fundamental to WPF data binding and then goes into the usage of the Binding class and other features of data binding.

This topic contains the following sections.

MSDN

Routed Event

Functional definition: A routed event is a type of event that can invoke handlers on multiple listeners in an element tree, rather than just on the object that raised the event.
Implementation definition: A routed event is a CLR event that is backed by an instance of the RoutedEvent class and is processed by the Windows Presentation Foundation (WPF) event system.
A typical WPF application contains many elements. Whether created in code or declared in XAML, these elements exist in an element tree relationship to each other. The event route can travel in one of two directions depending on the event definition, but generally the route travels from the source element and then "bubbles" upward through the element tree until it reaches the element tree root (typically a page or a window). This bubbling concept might be familiar to you if you have worked with the DHTML object model previously.
http://msdn.microsoft.com/en-us/library/ms742806.aspx#prerequisites

.Net Generics

Introduction

Generics are a new feature in version 2.0 of the C# language and the common language runtime (CLR)

When you use generics, you are creating classes or methods that use a generic type, rather than a specific type. For example, rather than creating a type-specific, you could create a reusable List class using generics.

How is that different from the ArrayList class?

The System.Collection.ArrayList can be used with any objectn, but no type checking is done when objects are passed to methods. You have to manually cast objects back to our type when retrieving; which makes the code harder.

Using the code

I have a Strongly Typed Class named "StudentList" and Generics Class named "MyCustomList" and a sample class named "Student".

"StudentList" class can accepts only Type of Student Objects for its Methods.

But "MyCustomList" Class can Accept any Type u specifying in "T"

Consider the class Student



Student dhas = new Student("Manick", "Dhas", 22);

Student raj = new Student("Sundar", "Raj", 32);

///Using a custom strongly typed StudentList

StudentList mc = new StudentList();
mc.Add(dhas);
mc.Add(raj);

Response.Write("Using a custom strongly typed StudentList
");

foreach (Student s in mc)
{
Response.Write("First Name : " + s.FirstName + "
");

Response.Write("Last Name : " + s.LastName + "
");

Response.Write("Age : " + s.Age + "

");

}
We can use MyCustomList like..

///Creating a list of Student objects using my custom generics

MyCustomList student = new MyCustomList();
student.Add(dhas);
student.Add(raj);

Response.Write("
Using a list of Student objects using my custom generics
");

foreach (Student s in student)
{
Response.Write("First Name : " + s.FirstName + "
");

Response.Write("Last Name : " + s.LastName + "
");

Response.Write("Age : " + s.Age + "

");

}

///Creating a list of Student objects using my custom generics

MyCustomList intlist = new MyCustomList();
intlist.Add(1);
intlist.Add(2);

Response.Write("
Using a list of String values using my custom generics
");

foreach (int i in intlist)
{
Response.Write("Index : " + i.ToString() + "
");

}

///Creating a list of Student objects using my custom generics

MyCustomList strlist = new MyCustomList();
strlist.Add("One");
strlist.Add("Two");

Response.Write("
Using a list of int values using my custom generics
");

foreach (string str in strlist)
{
Response.Write("Index : " + str + "
");

}