Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Tuesday, October 8, 2013

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