Posts

Showing posts from 2010
Image
  My dear Sachin... I love u :-)

C# Cloning

Introduction "Introduction Cloning C# objects is one of those things that appears easy but is actually quite complicated with many 'gotchas.' This articl..." Cloning C# objects is one of those things that appears easy but is actually quite complicated with many "gotchas." This article describes the most common ways to clone a C# object. Shallow vs. Deep Cloning There are two types of object cloning: shallow and deep. A shallow clone copies the references but not the referenced objects. A deep clone copies the referenced objects as well. Hence, a reference in the original object and the same reference in a shallow-cloned object both point to the same object. Whereas a deep-cloned object contains a copy of everything directly or indirectly referenced by the object. ICloneable Interface The ICloneable interface contains a single Clone method, which is used to create a copy of the current object. public interface ICloneable { object Clone(); } The problem wi...

The Great Rhino Mocks

What is Rhino Mocks? Rhino Mocks allows you to easily create mock objects and setup a wide range of expectations on them using strongly typed notation instead of compiler-opaque strings. It's as simple as: IProjectView projectView = mocks.StrictMock (); Expect.Call(projectView.Title).Return("Project's Title"); Definitions: Mock Object - an object that pretends to be another object and allows you to set expectations on its interactions with another object. Interaction Based Testing - you specify a certain sequence of interactions between objects, initiate an action, and then verify that the sequence of interactions happened as you specified it. State Based Testing - you initiate an action and then check for the expected results (return value, property, created object, etc). Expectation - general name for validation that a particular method call is the expected one. Record & Replay model - a model that allows for recording actions on a mock object and then replay...

Windows Communication Foundation (WCF) - Instance Context Mode

Introduction This article illustrates the use of the InstanceContextMode property used in the ServiceBehaviour attribute and how it can be so handy in the latest communication technology Windows Communication Foundation (WCF), introduced by Microsoft as a part of the .NET framework SDK 3.0 and later versions. I will be creating a demo application which will make use of the various instance context modes available in WCF, along with the explanation. Why WCF? I thought of providing a little information about why Windows Communication Foundation (WCF) is required in the .NET framework when there are already communication technologies like web services, enterprise services and remoting. WCF is introduced by Microsoft to achieve a Single Unified API for.NET services, so that in the future if any one speaks about service communication in .NET it would be only Windows Communication Foundation (WCF). Even though web service has proved to be stable it has a lot of limitations like statelessness...

Interview Questions - Part 2

When to use Interface? Use an interface when: There are a group of related methods that may be called. A class only needs one implementation of the method. The class using the interface will want to cast that interface to other interface or class types. The method being implemented is linked to the type or identity of the class: for example, comparison methods. When to use delegates? Use a delegate when: An eventing design pattern is used. It is desirable to encapsulate a static method. The caller has no need access other properties, methods, or interfaces on the object implementing the method. Easy composition is desired. A class may need more than one implementation of the method. Service contracts? Data Contracts? What keyword shadowing? What is keyword yield? What are different kinds of Cursors? What are different kinds of triggers? What is var? What is the difference between memory table v/s temp tables? Why u have not used cursors in ur project? When u ll go for win forms and web...

Message Headers for WCF Request

Often do we want to pass some data to some or maybe all our service operations. This data is usually context data such as user tokens (user information), or environmental preferences of the user or machine (in Respond terminology: UserConext object). In these kind of situations, we would rather not add additional context parameters to the contracts or our services, because we don’t want to involve implementation data / context data with the business parameters of our services. A nice and easy way to pass that data is to use MessageHeaders. In order to do this we follow these steps: Add the context data to the outgoing message headers. Call the operation (Nothing special here). Extract the data from the incoming message headers. Using an OperationContextScope In order to add the message header, you should have a OperationContext for your call. An OperationContext will automaticly be created for the call, and will be available in the service side. If one wishes to add the message he...

Security in WCF

Image
The first step to securing a WCF service is defining the security policy. Once you have established requirements for authentication, authorization, and message protection it is a matter of service configuration to enforce it. Your binding selection will influence the available configuration options for the service security policy. When you expose a service endpoint you select a binding that represents the appropriate communication protocol and message encoding format. For example, for intranet communications or systems behind the firewall, TCP protocol with binary message encoding is usually preferred. For Internet access, HTTP protocol is a typical choice using text or MTOM encoding (depending on the message size). A standard set of bindings satisfy these protocol and encoding choices. NetTcpBinding is the right choice for binary TCP communications that cross machine boundaries, BasicHttpBinding is the right choice for HTTP communications that must support legacy Web service protoco...

Interview Questions - Part 1

What is JQuery JQuery is a light weight JavaScript library which provides fast and easy way of HTML DOM traversing and manipulation, its event handling, its client side animations, etc. One of the greatest features of jQuery is that jQuery supports an efficient way to implement AJAX applications because of its light weight nature and make normalize and efficient web programs. What are the advantages of jQuery The advantages of using jQuery are: 1. JavaScript enhancement without the overhead of learning new syntax 2. Ability to keep the code simple, clear, readable and reusable 3. Eradication of the requirement of writing repetitious and complex loops and DOM scripting library calls

Serialization and Generics in WCF

Recently, I have been spending some time blogging about serialization. This is a small effort to go back over some of the basics prior to starting on WCF. Today, I am continuing the serialization subject by taking a closer look at generics in regards to serialization. This is actually a popular subject for a lot of newcomers to WCF. Many developers who are fond of generics will create a service that exposes some generic method. When they finally get ready to fire up the service and give it a trial run, they are quickly disappointed to discover that it doesn't work as expected. So, what should be done...? WCF does not support the use of generic methods for service operation . In other words, only concrete types can be used for service operations. Open generic types cannot be used. Now, it is important to clarify this is not a limitation of WCF. Rather, it is a limitation of WSDL, which is used to expose service metadata to consumers. There is no construct within WSDL to d...

Model View Controller

Image
Context The purpose of many computer systems is to retrieve data from a data store and display it for the user. After the user changes the data, the system stores the updates in the data store. Because the key flow of information is between the data store and the user interface, you might be inclined to tie these two pieces together to reduce the amount of coding and to improve application performance. However, this seemingly natural approach has some significant problems. One problem is that the user interface tends to change much more frequently than the data storage system. Another problem with coupling the data and user interface pieces is that business applications tend to incorporate business logic that goes far beyond data transmission. Problem How do you modularize the user interface functionality of a Web application so that you can easily modify the individual parts? Forces The following forces act on a system within this context and must be reconciled as you consider a solut...

Windows Communication Foundation - FAQ

Image
Difference between Web Service and WCF? 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. The DataContractAttribute can be applied to the class or a strcture. DataMemberAttribute can be applied to field or a property and theses fields or properties can be either public or private. Web Services : 1.It Can be accessed only over HTTP 2.It works in stateless environment WCF : WCF is flexible because its services can be hosted in different types of applications. The following lists several common scenarios for hosting WCF services; IIS WAS Self-hosting Managed Windows Service Important difference ...