Monthly Archives: December 2014

System.Data.Entity.Infrastructure missing Namespace


install the EntityFramework NuGet package which will setup everything for you .

Go to

menu “Tools”-> Library Package Manager –>  Package Manger Console
and typing there:
PM> install-package EntityFramework

That’s it. All errors disappeared.

Which SQL statement is faster? (EXISTS or IN …)


Based on Question asked in MSDN Forum

  1.  IN is efficient when most of the filter criteria is in the sub-query.
  2.  EXISTS is efficient when most of the filter criteria is in the main query.
  3.  Usually IN has the slowest performance.

For more you can refer Join vs Exists vs In (SQL)IN vs. JOIN vs. EXISTS

Which SQL statement is faster? (HAVING vs. WHERE…)


If a condition refers to an aggregate function, put that condition in the HAVING clause. Otherwise, use the WHERE clause.

You can use HAVING but recommended you should use with GROUP BY.

SQL Standard says that WHERE restricts the result set before returning rows and HAVING restricts the result set after bringing all the rows. So WHERE is faster.

About InstanceContextMode in WCF


InstanceContextMode tells how the instanceContext object need maintain/handle/available for the incoming messages.

What is the Use of InstanceContextMode?

Basically it tell how the object create for the request/response must be handle across the service.

In our Business requirement let see what are all different type of requirement you may face

1) For some of you request you may need to maintain information for the each user and its scope of information is limited to each user (SESSION)

EX:- While a client request to service first time new instance will get created after that request come form same client will handle by the same instance until it gets disconnected/Expired.

2) Some time you need to maintain the information common to all user request to share the information across all the clients

EX: Update each share value to the requested users.

3) Some other request just you want to pass information to service, which may return the value back to client or may not based on your need.

Let see how we can implement it using WCF InstanceContextMode
There are 3 different type of InstanceContextMode

1) PerCall
– For every request separate InstanceContext object gets created and destroyed after respond back to the client, just Request/Response pattern.
– Decorate [ServiceBehaviour(InstanceContextMode=InstanceContextMode.PerCall)] for the class that you want to include the InstanceContextMode.

2) PerSession
– When first time request comes from the client new object will gets created, after that when ever subsequent call comes from the same client, the request are handle by the same instance object. This object will alive in service untill the client get disconnect or that instance object goes to ideal mode for some time. Default session expire time is 10 min.
– Decorate [ServiceBehaviour(InstanceContextMode=InstanceContextMode.PerSession)] for the class that you want to include the InstanceContextMode.

3) Single
– This object is global for all the request/response. When ever new request are comes from the client it won;t create new instance because of that performance gets improved.
– Decorate [ServiceBehaviour(InstanceContextMode=InstanceContextMode.Single)] for the class that you want to include the InstanceContextMode.

Note:-

You need to decorate corresponding servicebehaviour attribute in the class, else it will behave as request/response fromat and also based on how you create object in client side to call the service.

To download the sample code click here

Callback in WCF using wsDualHttpBinding


When shall we go for wsDualHttpBinding?

Your service need to perform lot of operation after getting the information from the client side, which consume more time to return result back to the client.

Normally time consuming operation in server side will block the client to perform other operation. So  ‘wsDualHttpBinding’ will be ideal solution for this kind of problem.

Suppose if your client not depend on the result produce by the service at that time we can go for ‘wsDualHttpBinding’ .

If you need to implement callback between client and service at that time we can go for ‘wsDualHttpBinding’.

Because of some operation (or) result taking place in server side must not affect the client side access or other request the ideal choice is ‘wsDualHttpBinding’

wsDualHttpBinding is binding which sends the request in one http channel and response will be sent back to the client in another http channel

 

If you are using ‘dualHttpBinding’ you need to create two interface one interface is to get the request from the client and one more is send the response back to the client as callback

The below mentioned interface is to send the response back to the client and the ‘OperationalContract’ used to send the response back to the client must be decorated with the property ‘IsOneWay=true’ as shown below.

CalbackInterface

Another Interface mentioned below is to get the request from the client, this interface  must also be decorated with the property ‘IsOneWay=true’  inside the ‘OperationalContract’ attribute as mentioned below. Also we need to refer using which interface (or) channel we are going to send the response back to the client. We already declare the callback interface now need to establish relationship with the ‘ServiceContract’ as mentioned below.

ServiceContract

In the above code we are mentioned ‘INotificationServiceCalback’ as the callback interface by using ‘CallbackContract’ property of ServiceContract.

 

In the web.Config we need to specify ‘wsDualHttpBinding’ in the binding property.

WebConfig

 

The Implementation of service contract

ImplementationofDuplex

You can find the Code sample here