About Nuget

March 30, 2015 Leave a comment

In Visual studio to add any reference in our project we will use ‘Add Reference Dialogue’, but in last few years apart from .net assemblies, we are started incorporate lots of 3rd party libraries(.NET open source libraries) into our projects.If you manually add any .NET open source assemblies some time it takes too much effort to make it work with the project. We can avoid this manual configuration through Nuget Packages available for VS2010 and from VS2012 this feature is comes by default during installation.

Nuget is type of Open source Package management system and it is a huge repository. Using Nuget we can include required assembly in to out application. we can make use of Package Manager Console window in VS to install any external assembly that is available in Nuget.

Advertisements

Security issue in MVC delete using hyperlink

March 13, 2015 Leave a comment

In Stephen Walther post, he mentioned security issue in deleting the record through GET request. In MVC hyperlink will use GET request to delete a record, so any one can able to access the record just by passing the id of record.

Example:-

http://www.kethare.in/employee/delete/1

In the above example we are using GET request to delete the employee record by clicking the corresponding delete hyperlink of the employee. So the value that you are passing is known and any one who knows the delete URL can have possibility of deleting the record which is not advisable.

Stephen Walther provide solution to bypass this issue is using client side scripting (AJAX(or) JQUERY, JavaScript…)

System.Data.Entity.Infrastructure missing Namespace

December 29, 2014 Leave a comment

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.

Categories: MVC

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

December 9, 2014 Leave a comment

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

Categories: SQL Tags: , ,

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

December 9, 2014 Leave a comment

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.

Categories: SQL Tags: , ,

About InstanceContextMode in WCF

December 8, 2014 Leave a comment

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

December 5, 2014 Leave a comment

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

%d bloggers like this: