Saturday, September 22, 2012

WCF


1. FaultContract
2. MessageContract
3. Duplex
4. Hosting
5. Transactions
6. Session management
7. Polymorphism
8. tcpbinding





  1. FaultContract
    • FaultContract helps to do Exception handling in WCF service
    • convert .NET exceptions into Fault
    • Service client does not have to be built by using .NET framework
    • SOAP protocol provides a standard mechanism to report faults within SOAP message.
    • So client can recognize it as fault from the SOAP message

    • Types of error:
      • Domain error: (eg: NoFunds)
      • Technical error:  (Expected and                 unexpected technical errors(eg: divide by zero))
    • These errors should be mapped to one of the defined faults.
    • Structure of SOAP fault is an XML representation of error information.
    • SOAP fault contains
§ Code
§ Reason
§ Detail


    • Using Fault in service



    • Typed and Untyped fault


    • Handling service Exceptions at client


  1. MessageContract
    1. WCF allow you to control SOAP message structure with MessageContract
    2. You can modify message by

·   Define custom header
·   Adding elements to SOAP body
·   Altering namespace in SOAP body

  1. Message exchange patterns
    1. Request response
    2. Simplex (one way)
    3. Duplex

·         Request  response
o  default message exchange pattern in WCF
o Synchronous remote procedure call(RPC)

·         One way
o Client send message to service, but service does not send message back
o Return type of one-way operation must be void
o Drawback- no way to detect operation failure
o Advantage – performance – as client does not have to wait for response

[OperationContract(IsOneWay = true)]
void MakeDeposit(string account, decimal amount);



·         Duplex
o This pattern consists of 2 separate contracts
o One contract implemented by service, other by client
o 2 one-way messages


  1. Polymorphism
·         Operation overloading - Operation with same name, but different parameters
·         Use Name property in OperationContract.

[OperationContract(Name="DepositLocalCurrency")]
void Deposit(string account, decimal amount);

[OperationContract(Name="DepositAnyCurrency")]
void Deposit(string account, Currency amount);




  1. Transactions
@server:
    1. Select a transaction aware binding
o NetTcpBinding
o NetNamedPipeBinding
o wsHttpBinding
o wsDualHttpBinding
o wsFederationHttpBinding

    1. Enable TransactionFlow property of binding in configuration file.
 
   
         transactionProtocol="WSAtomicTransactionOctober2004"/>
 
    1. Transactional requirement of operation




@client
1.       Enable transaction flow on binding in configuration file.
2.       Use TransactionScope block at client code


Wednesday, September 12, 2012

ASP.NET MVC FAQ


1. Can you have viewstate in ASP.NET MVC?

  • Ans: No

2. Can you do unit testing of view in ASP.NET MVC?

  • Ans: Yes

3. Is routing happens every time a page request or only first time?

  • Ans: - Only first time
  • - Shared Sub RegisterRoutes(ByVal routes As RouteCollection)



http://jinaldesai.net/asp-net-mvc-3-interview-questions/

Tuesday, September 11, 2012

Datastructures in .NET


a.       Stack:
·   FILO (first in last out)
·   Push(object o) – insert an object at top of stack
·   POP() – removes object at top of stack
·   Peek() – returns object at top of stack without removing
·   One of the classic examples of stack in .net framework is in memory management of value types.
·   There are non generic collection stack object (System.Collections.Stack) and generic collection stack object (System.Collections.Generic.Stack)



b.      Queue:
·   FIFO
·   Enqueue(object o) – add an object at end of queue
·   Dequeue() – remove object at beginning of queue
·   Peek() - return object at beginning of queue
·   First object entering to the Queue, exits first
·   One of the classic example of queue implementation in MSMQ
·   Queue is used in the highly reliable communication scenarios. Even if the message channel not available, messages are stored in the queue and transmitted once the channel is up.
·   There are non generic collection object (System.Collections.Queue) and generic collection object (System.Collections.Generic. Queue)


c.       Hashtable           
·   Hashtable stores key – value pair
·   Is organized based on the hash code of the key
·   Each element in hashtable is stored as DictionaryEntry object
·   A key cannot be null, but value can be
·   It is a non generic collection System.Collections type
·   Hashtable stores types of object
·   There is a type conversion required every time when we use hashtable

IDictionary, ICollection, IEnumerable, ISerializable, IDeserializationCallback, ICloneable

d.      Dictionary
·   Dictionary is similar to Hashtable (key-value pair storage)
·   It is a generic collection (System.Collections.Generics)
·   Type of the object to store in the dictionary should specify at compile time
·   Performance wise,  Dictionary is better option that Hashtable
IDictionary, ICollection<KeyValuePair>, IEnumerable<KeyValuePair>, IDictionary, ICollection, IEnumerable, ISerializable, IDeserializationCallback

e.      List
·   It is generics collection (System.Collections. Generics)
·   It represents strongly typed list of objects
·   Consider a scenario to store all the employee names of Satyam, then use List
·   No type conversion required hence preferred over ArrayList

IList, ICollection, IEnumerable, IList, ICollection, IEnumerable

f.        ArrayList
·   ArrayList is a non generic collection (System.Collections)
·   Size can be dynamically increase
·   ArrayList stores objects
·   Type conversion required every time when use AL
·  This affects the performance

Dependency Injection in .NET

Three Ways to Implement Dependency Injection in .NET Applications

http://www.devx.com/dotnet/Article/34066

Monday, September 10, 2012

Struct in C#.NET

            //NOTES: STRUCT

            // - struct is a value type 
            // - no need to use new keyword
            // - cannot inherit from struct(error: cannot derive from sealed type)
            // - struct allows properties/method which uses reference type.



namespace StructSample
{
    class Program
    {
        static void Main(string[] args)
        {
            Point p;
            p.x = 10;
            p.y = 20;

            p.name = "wgi";

            Console.WriteLine(p.Add());

            Console.Read();
        }
    }


    struct Point
    {
        public int x, y;

        public string name;

        public int Add() { return x + y; }
    }


    //class newPoint : Point
    //{
    //}
}

E-Book Gallery for Microsoft Technologies