Pages

Thursday, May 31, 2012

Versioning WCF Project




In this article I will be explaining Contract versioning in WCF.
Once the service is developed and rolled over to production, any changes in contracts should be backwards compatible so that existing clients are not affected when changes are deployed. We will explore the effects of changes in Data Contract and Service contracts and try to adopt a versioning strategy depending on the scenario.
I will explain further by examples

Monday, April 16, 2012

Fault Contract in WCF


Exceptions are technology specific. Hence they cannot cross service boundaries. Soap represent standard for errors.WCF can transfer error from service to client through faults. If the error is a fault Exception then all the details are transferred else only generic fault.
i.e. InternalServiceFault
we can use either [ServiceBehavior] or to enable Fault.
Example:-
<serviceBehaviors>
        <behavior>
         
          <serviceMetadata httpGetEnabled="true"/>
         
          <serviceDebug includeExceptionDetailInFaults="True"/>
        behavior>
      serviceBehaviors>

You can throw a Soap Fault using the FaultException class
You can specify the fault code and reason when you create it. All this details will be traveled to the client side.
Example:-
 Throw New FaultException(Of FaultExceptionClass)(New FaultExceptionClass)
At the client side we can use the try catch block to catch this faultException
Example:- Catch ex As FaultException(Of FaultService.FaultExceptionClass)
            Console.WriteLine("Fault value " + ex.Detail.m_Reason)
            Console.WriteLine("Fault value " + ex.Detail.m_InnerReason)
Example:-

Tuesday, March 20, 2012

How to handle error and result in Diagnostics.process


Diagnostics.process provides access to local and remote processes and enables you to start and stop local system processes.
The Process component is a useful tool for starting, stopping, controlling, and monitoring applications. Using the Process component, you can obtain a list of the processes that are running, or you can start a new process. A Process component is used to access system processes
If you start any Process by Diagnostics.process object then to get the error in that process you have to raise ErrorDataReceived event. Below I have written a simple example.

Monday, March 19, 2012

How to get the location of software installed in server machine.


You can check the Registry Key for the Software installed location. You can do this by your VB code and run the exe you want in that location.
I will explain you this with a small example.

Sunday, March 18, 2012

Events in .net with example


An event is a message sent by an object to signal the occurrence of an action. The action could be caused by user interaction, such as a mouse click, or it could be triggered by some other program logic. The object that raises the event is called the event sender. The object that captures the event and responds to it is called the event receiver.
In event communication, the event sender class does not know which object or method will receive (handle) the events it raises. What is needed is an intermediary (or pointer-like mechanism) between the source and the receiver. The .NET Framework defines a special type (Delegate) that provides the functionality of a function pointer.
The Observer pattern is one of the most well known patterns used in software engineering. This pattern states that a non-determined number of business entities – called subscribers – are interested in a change of state of another business entity – called publisher – and that the publisher does not care who these subscribers are or what and why they are concerned with its change of state.
Let me explain you this by small example.

Difference between Static Polymorphis and Dynamic Polymorphism


What is Static Polymorphism?
What is Compile time Polymorphism?
What is Early binding?
What is Dynamic Polymorphism?
What is Runtime time Polymorphism?
What is Late binding?
These are most confusing questions, these things you use when you write code daily. But unless you prepare for interview, if someone ask you then you will be confused with this concepts.
In this small article, I will explain you what is static polymorphism and dynamic polymorphism?

Overriding the ToString Method


Every class and object includes the ToString method. By default, this returns a string containing the name of your custom class or structure. By overriding this method, you can return more meaningful, human-readable information about your objects.
Every object  gets the ToString method, which returns a string representation of that object. For example, all variables of type int have a ToString method, which enables them to return their contents as a string.
All classes and structures are based upon the Object class, so every such item that you define automatically inherits the ToString method
Lets us look into one simple example.


Friday, March 16, 2012

Delegates with Example


In this article I will to share with you, what is Delegates with a small example?
Well we can define Delegates as a type safe “Function Pointer” which holds references to static or instance methods. Delegates are used to call methods dynamically at runtime.
Example:-