Monday, August 31, 2020

Top 50 WCF Interview Questions

August 31, 2020

Top 50 WCF Interview Questions

1)      What is WCF?

2)      Why should we use WCF service?

3)      What are the features and advantage of WCF?

4)      What is the difference between WCF and Web services?

5)      What is a service contract in WCF?

6)      Explain what is SOA?

7)      What is transport in WCF?

8)      What is data contract in WCF?

9)      What is WCF binding and how many of them do you know?

10)   What are possible ways of hosting a WCF service?

11)   What is message contract in WCF?

12)   What is operation contract in WCF?

13)   What is contract in WCF service?

14)   WCF VS ASP.NET WEB API

15)   What is fault contract in WCF?

16)   What are end points and how many types of end points in WCF?

17)   What is address in WCF?

18)   Explain transactions in WCF?

19)   What is self hosting in WCF?

20)   What are the main components of WCF service?

21)   How do we host WCF service in IIS?

22)   What is one way operation?

23)   Why do we need one way service?

24)   What is WCF throttling?

25)   What is a service proxy in WCF?

26)   What is WCF concurrency and how many modes of concurrency in WCF?

27)   What is REST and how to create a WCF RESTful service?

28)   What is exception handling in WCF and what are the ways for WCF exception handling?

29)   What is tracing in WCF?

30)   Could we use WSHttpBinding with Request-CallBack exchange pattern?

31)   What replaces WCF in .Net Core?

32)   What is the knownType attribute in WCF?

33)   How to create Basic HTTP Binding in WCF?

34)   What is the difference between BasicHttPBindng and WsHttpBinding?

35)   What is transport level security in WCF?

36)   What is MSMQ in WCF?

37)   What is method overloading in WCF?

38)   What is WCF messaging layer?

39)   What is instance management in WCF?

40)   What is service versioning?

41)   What WCF data service?

42)   How does software as a service work?

43)   Which is the namespace used to access WCF?

44)   Why we use information cards in WCF?

45)   What is a formal agreement in WCF?

46)   How to create multiple methods in the same name?

47)   What is the address formats of the WCF transport schemas?

48)   How to set the timeout property for the WCF service client call?

49)   How can you generate proxies using Svcutil in WCF?

50)   What is the usage of receiveTimeout property in WCF?

 



Sunday, August 30, 2020

Difference between ref and out parameters in C#

August 30, 2020

 Ref and out keywords in c# are used to pass arguments within a method or function. Both indicate that an argument passed by reference. By default parameter are passed to a method by value. By using these keywords we can pass a parameter by reference.

Ref –

The ref keyword is used to pass an argument as a reference. This means that value of that parameter is changed in method, it get reflected in calling method.

Example : Ref  Keyword – C#

 
 public static string GetNextName(ref int id)  
  {  
    string returnText = "Next-" + id.ToString();  
    id += 1;  
    return returnText;  
  }  
 static void Main(string[] args)  
  {  
    int val = 1;  
    Console.WriteLine("Previous value of integer val:" + val.ToString());  
    string test = GetNextName(ref val);  
    Console.WriteLine("Current value of integer val:" + val.ToString());  
  } 
 

 

Output -

Previous value of integer val : 1

Current value of integer val : 2

 

Out –

The out keyword is used to pass arguments to method as a reference type and is primary used when a method has to return multiple values.

Example : Out  Keyword – C#

 
 public static string GetNextNameByOut(out int id)  
  {  
    id = 1;  
    string returnText = "Next-" + id.ToString();  
    return returnText;   
  }  
 static void Main(string[] args)  
  {  
    int val = 0;  
    Console.WriteLine("Previous value of integer val:" + val.ToString());  
    string test = GetNextNameByOut(out val);  
    Console.WriteLine("Current value of integer val:" + val.ToString());  
  } 
 

Output -

Previous value of integer val : 0

Current value of integer val : 1


Ref Vs Out

Ref Keyword            

Out Keyword

When ref keyword is used the data may pass in bi-directional.

When out keyword is used the data only passed in unidirectional.

In called method, It is not required to initialize the parameter passed as ref.

In called method, It is required to initialize the parameter passed as out.

Ref should not be used to return multiple values from method.

Out should be used to return multiple values from method.

Ref is useful when we already know the parameter value and called method can only modify the data.

Out is useful when we don't know the parameter value before calling the method.


Saturday, August 29, 2020

Major Events in Global.asax File

August 29, 2020

 

 Global.asax file is derived from the HttpApplication class and contains code for responding to application-level events raised by ASP.NET. Global.asax file, also known as ASP.NET application file, is located in root directory of an ASP.NET application.



Note 1 : The Global.asax is an optional file. Use it only when there is a need for it.

Note 2 : If a user requests the Global.asax file, the request is rejected . External users can not use it.

The following are some of the important events in the Global.asax file:

Application_Init : The Application_Init event is fired when an application initializes the first time.

Application_Start  : The Application_Start event is fired the first time when an application starts.

Application_AutorizeRequest : Application_AutorizeRequest event is  fired on successful authentication of users credentials. You can use this method to authorization rights to user.

Application_ResolveRequestCache : Application_ResolveRequestCache is fired on successful completion of an authorization request.

Application_Disposed : Application_Disposed  event is fired when the web application is destroyed.

Session_Start : Session_Start event is fired when session starts on each new user requesting a page.

Application_BeginRequest :  The Application_BeginRequest event is fired when each time new user request come in.

Application_EndRequest : The Application_EndRequest event is fired at the end of each request.

Application_AuthenticateRequest : The Application_AuthenticateRequest event indicates that a request is ready to be  authenticated. If you are using forms Authentication, this event can be used to check for the user’s roles & rights.

Application_Error : The Application_Error event fired when an error occurs.

Session_End : The Session_End event is fired when the session of a user ends.

Application_End : The Application_End event is fired when the web application ends.

Sunday, August 23, 2020

Partitioning Operator: Take & TakeWhile

August 23, 2020

In LINQ, Partition Operators are used for separating the given sequence into two portions without

Sorting the element and return the one of the portions


Method

Description

Take

This operator is used fetch the first “n” number of elements from the data source where “n” is integer which is passed as a parameter to the Take method.

TakeWhile

This operator behaves similarly to the take() method except that instead of taking the first “n” element of sequence , It takes all of initial elements of sequence that meet the criteria specified by the predicate, and stops on the first element that doesn’t meet the criteria

 

Example: Take() Method – C#

 

IList<string> strList = new List<string>(){ "One", "Two", "Three" };
 
var newList = strList.Take(2);
 
foreach(var str in newList)
    Console.WriteLine(str);

 

 

Output -

One

Two

 

Example: TakeWhile() Method – C#

 
IList<string> strList = new List<string>() { 
                                            "Three", 
                                            "Four", 
                                            "Five", 
                                            "Hundred"  };
 
var result = strList.TakeWhile(s => s.Length > 4);
 
foreach(string str in result)
        Console.WriteLine(str);

 


Output -

Three


Saturday, August 15, 2020

Partitioning Operator: Skip & SkipWhile

August 15, 2020

 

In LINQ, Partition Operators are used for separating the given sequence into two portions without

Sorting the element and return the one of the portions


Method

Description

Skip

This operator is used to skip the specified number of elements in a sequence return the remaining elements.

SkipWhile

This operator is used to skip the elements in a sequence based on the condition, Which is defined as true

 

Example: Skip() Method – C#

 

IList<string> strList = new List<string>(){"Hindi""Marathi""Math""Science"};

 

var newList = strList.Skip(2);

 

foreach(var str in newList)

    Console.WriteLine(str);

 

 

Output -

Math

Science

 

Example: SkipWhile() Method – C#

 
IList<string> strList = new List<string>() { 
                                            "One", 
                                            "Two", 
                                            "Three", 
                                            "Four", 
                                            "Five", 
                                            "Six"  };
 
var resultList = strList.SkipWhile(s => s.Length < 4);
 
foreach(string str in resultList)
        Console.WriteLine(str);

 



Output -

Three
Four
Five
Six


Thursday, August 13, 2020

Difference between Deferred execution and Immediate execution

August 13, 2020

 LINQ queries are always executed when the query variable is iterated over, not when the query variable is created. This is called deferred execution. You can also force a query to execute immediately, which is useful for caching query results.


There are two type of linq query execution are given below:

Deferred query execution

In deferred execution query is executed when the query variable is iterated by using loop.
Deferred execution enables multiple queries to be combined or queries to be extended. when a query is extended, it is modified to include the new operations, and the eventual execution will reflect the changes.

DataContext objcontext = new DataContext();
var query = from customer in objcontext.Customers
where customer.City == "Pune" select customer; // Query does not execute foreach (var Customer in query) // Query executes { Console.WriteLine(Customer.Name); }

Deferred execution provides the facility of query reusability since it always fetches the uploaded data from the data source which exists at the time of each execution.

Immediate Query Execution

In immediate execution query is executed at the point of its declaration. It is the query that return a singleton value are executed immediately. Some example of singleton queries are
Average, Count, First and Max . These execute immediately because the query must produce a sequence to calculate the singleton result.

DataContext objcontext = new DataContext();
var query = (from customer in objcontext .Customers
where customer.City == "Pune" select customer).Count(); // Query execute
Immediate execution does not provide the facility of query re-usability. you could also force execution by putting the foreach or For Each loop immediately after the query expression, but by calling ToList or ToArray you cache all the data in single collection object.





Friday, June 19, 2020

Populate dropdownlist using jquery

June 19, 2020


Step 1-

 Create the required tables and stored procedures

Table Script -

Create Table DepartmentTable
(
 Id int identity primary key,
 DepartmentName nvarchar(20)
)
Go

Insert into DepartmentTable values ('Science')
Insert into DepartmentTable values ('Arts')
Insert into DepartmentTable values ('Commerce')
Go

Stored Procedure -

CREATE PROCEDURE USP_GetDepartment
AS
BEGIN
 Select IdDepartmentName from DeparmentTable 
END
GO

Step 2-

Create new asp.net web application project. Name it JqueryDemo. 


Step 3-

Include a connection string in the web.config file to your database.
<add name="CS"
      connectionString="server=.;database=SampleDB;integrated security=SSPI"/>


Step 4-

Add a class file to the project. Name it Department.cs. Copy and paste the following code. 

namespace JqueryDemo
{
    public class Department
    {
        public int Id { getset; }
        public string DepartmentName getset; }
    }
}


Step 5-

Add a WebService (ASMX) to the project. Name it WebService.asmx. Copy and paste the following code. 

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
using System.Web.Services;

namespace JqueryDemo
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class WebService: System.Web.Services.WebService
    {
        [WebMethod]
        public void GetDepartment()
        {
            string cs = ConfigurationManager.ConnectionStrings["CS"].ConnectionString;
            List<DepartmentDepartmentnew List<Department>();
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("USP_GetDepartment", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    Department ObjDepartment = new Department();
                    ObjDepartment.Id = Convert.ToInt32(rdr["Id"]);
                    ObjDepartment.Name = rdr["DepartmentName"].ToString();
                    Department.Add(ObjDepartment);
                }
            }
            JavaScriptSerializer js = new JavaScriptSerializer();
            Context.Response.Write(js.Serialize(Department));
        }


Step 6-

 Add a WebForm to the ASP.NET project. Copy and paste the following HTML and jQuery code. 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
  
    </style>
    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var DDLDepartment = $('#DDLDepartment');
            $.ajax({
                url: 'WebService.asmx/GetDepartment',
                method: 'post',
                dataType: 'json',
                success: function (data) {
                    DDLDepartment.append($('<option/>', { value: -1, text: 'Select Department' }))
                    $(data).each(function (index, item) {
                        DDLDepartment.append($('<option/>', { value: item.Id, text: item.DepartmentName }));
                    });
                },
                error: function (err) {
                    alert(err);
                }
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <table align="center" style="width: 261px">
                <tr>
                    <td>
                        <asp:Label ID="lblDepartment" runat="server" Text="Department : "></asp:Label></td>
                    <td>
                        <asp:DropDownList ID="DDLDepartment" runat="server">
                        </asp:DropDownList></td>
                </tr>
            </table>

        </div>
    </form>
</body>
</html>