URDINESH: C# Interview Questions
Showing posts with label C# Interview Questions. Show all posts
Showing posts with label C# Interview Questions. Show all posts

Wednesday, May 14, 2014

WCF Interview Questions Part 1

1)      Explain different type of binding in WCF

  • WCF provides nine built-in bindings:
1.   BasicHttpBinding: Basic web service communication. Exposes WCF services as legacy ASMX web services. Used for interoperability. No security by default.
2.     WSHttpBinding: Web services with WS-* support. Supports transactions and reliable messaging.
3.     WSDualHttpBinding: Web services with duplex contract and transaction support.
4.     WSFederationHttpBinding: Web services with federated security. Supports transactions.
5.     MsmqIntegrationBinding: Communication directly with MSMQ applications. Supports transactions.
6.     NetMsmqBinding: Communication between WCF applications by using queuing. Supports transactions.
7.     NetNamedPipeBinding: Communication between WCF applications on same computer. Supports duplex contracts and transactions.
8.     NetPeerTcpBinding: Communication between computers across peer-to-peer services. Supports duplex contracts.
9.     NetTcpBinding: Communication between WCF applications across computers. Supports duplex contracts and transactions.

2)      Explain different type of contracts available in WCF

Contract is platform-neutral and standard way of describing what services does. In WCF, all services are exposed as contract. There are four types of contracts :

Service Contract – It describes operation provided by service. A service should contain at least one service contract. Service Contract is defined by using [ServiceContract] attribute, it is similar to [WebMethod] of Web Services.

Data Contract – It describes data exchange between service and client. Data Contract is defined using [DataContract] and [DataMember] attribute.

Message Contract – It transfers information from service to client. WCF uses SOAP message format for communication.

Fault Contract – It handles and convey error message to the client when service get error.


3)     We have a large amount of data with us, which should be passed as an input to WCF service. What type of binding will you use?

netTcpBindingbinnding


ASP.NET Interview Questions and Answers Part 1

1)      What is view state?

=> When a form is submitted in classic ASP, all form values are cleared. Suppose you have submitted a form with a lot of information and the server comes back with an error. You will have to go back to the form and correct the information. You click the back button, and what happens.......ALL form values are CLEARED, and you will have to start all over again! means The site did not maintain your ViewState.

=> When a form is submitted in ASP .NET, the form reappears in the browser window together with all form values. How come? This is because ASP .NET maintains your ViewState. 

=> The ViewState indicates the status of the page when submitted to the server. The status is defined through a hidden field placed on each page with a <form runat="server"> control.

2)      Where these view state will be saved?

=> Viewstate is stored on page it self in encoded form. You can't access the viewstate in client side in a direct manner. You need to know the encoding/decoding algorithms to fetch the valuable data from this viewstate in clientside code.

=> You can use hidden variable to store data that will be used only on that page. Hidden variables are accessible from client side and server side code.

=> You can use Cache or session to store datatable (large data). They will have good performance as compare to ViewState.

=> The Cache is always using the machine's memory, the Session uses what has been configured:
=> In a web farm the Session can be local (which works only if affinity is set), or remote (state server or database, or custom), but the cache is always local.
=> So, storing a DataTable in the cache will consume memory, but it will not use serialization.

PS: storing a DataSet instead of a DataTable will change almost nothing.

3) Disadvantages of view state.

These are the main disadvantages of using View State:

1. It can be performance overhead if we are going to store larger amount of data , because it is associated with page only.

2. Its stored in a hidden filed in hashed format still it can be easily trapped.

3. It does not have any support on mobile devices.


4)  If there is a login page and a user gives his credentials, u have to authenticate it and display the user name in all other pages? How will u do it? What concept will u use for it?

for the current structure of your project, you can create a Session variable on the login page after verifying the user credentials and store logged in user details i.e.
in your login page, login button click handler do this: 

protectedvoidbtnLogin_Click(object sender, EventArgs e)
{
    string username= txtUsername.Text;
    string pwd = txtPassword.Text;
    //call your logic to verify user credentials.
    VerifyUserCredentialFromDb(username, pwd);
    if(UserValid)
    {
        Session["User"] = GetUserObject(username,pwd);
        //whatever your logic is, make sure, you create the Session object, before
        //below line,whereever you are doing it
        Response.Redirect("Home.aspx");
    }
}


and in the Page_load of all the other pages


protectedvoidPage_Load(object sender, EventArgs e)
{
     if(Session["User"]==null)
      Response.Redirect("login.aspx");
   }      
                                                                                                                                      

5)     What are cookies?

=> A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.

=> Cookies provide a means in Web applications to store user-specific information. For example, when a user visits your site, you can use cookies to store user preferences or other information. When the user visits your Web site another time, the application can retrieve the information it stored earlier.

6)     How to access the values globally throughout the application in .NET?

Session Variables Session variables are stored in the server's memory for each user, and can be read and written to as often as required. These are limited to a per-user basis, so if you want to hold a single variable for all users, then this isn't the way to go.

Usage:
Session["MyVariable"] = 5;
intmyVariable = (int)Session["MyVariable"]; //Don't forget to check for null references


7)     Various modes of storing ASP.net session

ASP.NET session state supports several different storage options for session data. Each option is identified by a value in the SessionStateMode enumeration. The following list describes the available session state modes:

  • InProc mode, which stores session state in memory on the Web server. This is the default.
  • StateServer mode, which stores session state in a separate process called the ASP.NET state service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.
  • SQLServer mode stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.
  • Custom mode, which enables you to specify a custom storage provider.
  • Off mode, which disables session state.
8)     Types of authentication in .NET? 

  •  There are three ways of doing authentication and authorization in ASP.NET:-
    • Windows authentication: - In this methodology ASP.NET web pages will use local windows users and groups to authenticate and authorize resources.

    • Forms Authentication: - This is a cookie based authentication where username and password are stored on client machines as cookie files or they are sent through URL for every request. Form-based authentication presents the user with an HTML-based Web page that prompts the user for credentials.

    • Passport authentication :-Passport authentication is based on the passport website provided
    by the Microsoft .So when user logins with credentials it will be reached to the passport website ( i.e. hotmail,devhood,windows live etc) where authentication will happen. If Authentication is successful it will return a token to your website.

    • Anonymous access: - If you do not want any kind of authentication then you will go for Anonymous access.
9)     Explain about Partial classes?

There are several situations when splitting a class definition is desirable:
  • When working on large projects, spreading a class over separate files enables multiple programmers to work on it at the same time.
  • When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when it creates Windows Forms, Web service wrapper code, and so on. You can create code that uses these classes without having to modify the file created by Visual Studio.
  • To split a class definition, use the partial keyword modifier, as shown here:
C#
public partial class Employee
{
public voidDoWork()
{
}
}

public partial class Employee
{
public voidGoToLunch()
{
}
}
The partial keyword indicates that other parts of the class, struct, or interface can be defined in the namespace. All the parts must use the partial keyword. All the parts must be available at compile time to form the final type. All the parts must have the same accessibility, such as public, private, and so on.

10)     Difference between Dataset.clone and dataset.copy?

Clone :- copies only the structure of the dataset. it includes all datatable schemas their constraints and exlcuding data in those datatables.

DataSet dswithData;//this is containing datatable schamas
DataSet dsNew;
dsNew=dswithData.Clone();


while Copy() : methods copies all the dataset including its datatables schemas, constraints along with the data.

<prelang="cs">
DataSetdswithData;//this is containing datatableschamas
DataSetdsNew;
dsNew=dswithData.Copy();
</pre>

Followers