WCF Transaction Example

Create a client application to consume the 3 services created by the transactions

Create a new web site with the name  WCF traction client à Design the page à add references 3 WCF services created early in this program

  1. For WCF customer service with reference name as ‘SFC’ (service reference for customer)
  2. For WCF merchant service with reference name as “SRM”
  3. To WCF transaction service with reference  name as “SRT” add reference to “System

Transactions” Namespace 11 write the following

code using system data sqlclient;

using system Transactions;

using SRC;

using SRM;

using SRT;

sqlconnection con= new sqlconnection (“---“) ;

protected void btnsubmit_click(----)

{

Screenshot_78

  1. strings = “select c balance from customer where c ID=’ “ + extcid.text + “ ‘ “ ;

    Open ();

    sqlcommand cmd = new sql command (s, con);

    sqldata reader Dr = cmd. Execute reader ();

    Dr. Read ();

    double cbal = convert . to Double ( Dr [0]);

    cbal = cbal – convert. To Double (txtamt.text);

Con.close();

s= “select cbalance from merchant where MID = ‘ “cmd = new sql command (s, con);

con opend();

Dr = cmd. Execute reader();

DR. Read ();

double M Bal = convert. Tobouble (DR[0]);

MBal = MBal + convert . to double (txt Tamt.text);

con.close();

if (<bal<0)

lbl display text ‘balance is not sufficient, transaction cannot be performed”;

else

{

using (transaction scope TS = new transaction scope option. Required)

{

try

{

customer client objc = new customer clinet ();

Merchant client objM = new merchant client ();

Transaction client objT = new Transaction client ();

objc update customer (txtcId. Text, cbal);

objM. Insert transaction ((txt Tid – text, text Cid. Text, txt Mid. Text, datatime. Now .date, convert. To bouble / txt tamt. Text), cbal, mbal);

T.S.complete();

lbldisplay.text = “Transaction successful”;

}

catch

{

TS dispose ();

lbldisplay.text =”Transaction Rooled back”;

}

}

}