• Home
  • About
  • BestBloggingIdeas
  • DotNetLearningSource
  • FORUM
  • Joblinks
  • Latest News
  • Policy
  • POSTS
  • SimplySqlServer.Com && SimplyAspDotNet.Com
  • Sitemap

Join Ours Forum

Asp.Net,C#,Ajax,Sql server,silverlight,Javascript codes exambles articles,Programming exambles

RSS Feed
  • Bounty Huge Roll [Amazon Frustration-Free Packaging]
  • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
  • The Basic Overview of Windows Mobile Development Asp.Net C#
  • Overview of Sql server extended properties Asp.Net C#
  • How to Use Sql Server Extended properties using visual studio Asp.Net C#
  • Adobe Dreamweaver Templates Accelerate Web Development
  • Top Tips for Web Design Projects
  • How to Achieve a Good Web Design Structure
  • To Use Or Not To Use Website Templates
  • Five Tips to a Successful Website
  • Top 10 Articles,


    Silverlight Datagrid Select Update Delete Insert Asp.Net C#

    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net

    Performing Developing Using Investigating Asp.Net 2.0 Ajax Application Development Asp.Net C#

    Hosting/Install Wcf Services in a Windows Service Asp.Net C#

    Connecting Silverlight to Wcf Asp.Net C#

    Silverlight Data Grid Data Binding WCF Asp.Net C#

    Invoking/Accessing/Calling WCF Service Without Adding/Creating Proxy/Reference Asp.Net C#

    Performing Doing Creating Insert Update Delete sql data Using Linq Database Asp.Net C#

    Do/perform/create transactions in wcf asp.net c#/Code for wcf transactions

    Posted by on July 18, 2010 Leave a comment (2) Go to comments

    Introduction:
    In this article,i am going to explain about how to perform transactions in wcf using asp.net and c#.

    Main:
    Transactions are fundamental to applications in order to ensure consistent behavior for data.
    In addition, they are a fundamental building block for ensuring the implementation of atomic,
    consistent, independent, and durable (ACID) behavior in an application.

    WCF supports WebServices-Atomic transaction protocol.System.ServiceModel namespace helps us to
    perform transaction in wcf,and also it contains 3 main components for supporting transactions.
    There are,
    ServiceBehavior attribute,
    OperationBehavior attribute,
    TransactionFlow attribute

    The available transactionflow options are allowed,notallowed,mandatory.For performing transactions
    in wcf service please set transactionflow.mandatory in operation contract,

    See this below demo,

    Step 1: Create a service with transaction flow,
    service
    copy and paste the below code,

    using System;
    using System.ServiceModel;
    using System.Transactions;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Collections.Generic;
    using System.Globalization;
     
    namespace TransactionDemoSvc
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
     
        [ServiceContract]
        public interface IEmpService
        {
            [OperationContract]
            [TransactionFlow (TransactionFlowOption.Mandatory)]
            void InsertEmployee(string Query);
     
            [OperationContract]
            [TransactionFlow (TransactionFlowOption.Mandatory)]
            void UpdateEmployee(string Query);     
     
        }
     
        [ServiceBehavior(
            TransactionIsolationLevel = System.Transactions.IsolationLevel.Serializable ,
            TransactionTimeout = "00:00:30",
            ReleaseServiceInstanceOnTransactionComplete = false,
            TransactionAutoCompleteOnSessionClose = false,
            IncludeExceptionDetailInFaults = true)]
        public class EmpService : IEmpService
        {
              [OperationBehavior(TransactionScopeRequired=true)]
              public void InsertEmployee(string Query)
              {
              SqlConnection local_conn = new SqlConnection("Data Source=CHANDRU-PC;Initial Catalog=master;Integrated Security=True");
              local_conn.Open();
              SqlCommand local_cmd = new SqlCommand(Query, local_conn);
              local_cmd.ExecuteNonQuery();
              local_conn.Close();
              }
     
              [OperationBehavior(TransactionScopeRequired=true)]
              public void UpdateEmployee(string Query)
              {
              SqlConnection local_conn = new SqlConnection("Data Source=CHANDRU-PC;Initial Catalog=master;Integrated Security=True");
              local_conn.Open();
              SqlCommand local_cmd = new SqlCommand(Query, local_conn);
              local_cmd.ExecuteNonQuery();
              local_conn.Close();
              }
     
     
        }
    }

    Step 2:Host the Service,

    File –> New –> Project and select console application and named it wcfhost,

    steps involved,

    1.Add System.ServiceReference,
    2.Add TransactionDemoSvc dll,

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.ServiceModel.Description;
    using System.ServiceModel.Transactions;
     
    using TransactionDemoSvc;
     
    namespace WcfHost
    {
        class Program
        {
            static void Main(string[] args)
            {
                ServiceHost local_sh;
     
                Uri local_Namedpipe = new Uri("net.pipe://localhost/NetNamedPipeBinding");
                Uri local_tcp = new Uri("net.tcp://localhost:8000/TcpBinding");
     
                local_sh = new ServiceHost(typeof(EmpService), local_tcp, local_Namedpipe);
     
                //NetNamedPipeBinding local_pb = new NetNamedPipeBinding();
                NetTcpBinding local_tcpb = new NetTcpBinding();
     
                ServiceMetadataBehavior local_mbehave = new ServiceMetadataBehavior();
                local_sh.Description.Behaviors.Add(local_mbehave);
                local_sh.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
                //local_sh.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
                //local_sh.AddServiceEndpoint(typeof(IEmpService), local_pb, local_Namedpipe);
                local_sh.AddServiceEndpoint(typeof(IEmpService), local_tcpb, local_tcp);
                //TransactionFlowAttribute objattr = new TransactionFlowAttribute(TransactionFlowOption.Mandatory);
     
                local_tcpb.TransactionFlow = true;
     
     
     
                local_sh.Open();
     
                Console.WriteLine("Service Running");
                Console.ReadLine();
     
            }
        }
    }

    host
    Step 3:Create a client,
    client4
    Steps Involved,

    1.Make wcfhost service is running,
    2.Select add reference and add the empservice,
    addrefer
    client app code,

     ServiceReference1.EmpServiceClient objsvcclient = new ServiceReference1.EmpServiceClient();
     
     using (TransactionScope local_trans = new TransactionScope())
                {
                    string Query1 = String.Format("Insert into emp(empid,deptname,salary,manager) values ({0},'{1}','{2}','{3}')",
                                                  6454,
                                                  "SoftWares",
                                                  "700000",
                                                  "James");
     
     
                    string Query2 = String.Format("Insert into emp(empid,deptname,salary,manager) values ({0},'{1}','{2}','{3}')",
                                                  6455,
                                                  "SoftWares",
                                                  "600000",
                                                  "Nancy");
     
                    string Query3 = String.Format("Insert into emp(empid,deptname,salary,manager) values ({0},'{1}','{2}','{3}')",
                                                  66455,
                                                  "IT",
                                                  "5000",
                                                  "Peter");
                    objsvcclient.InsertEmployee(Query1);
                    objsvcclient.InsertEmployee(Query2);
                    objsvcclient.InsertEmployee(Query3);
     
                    local_trans.Complete();
                }
    MessageBox.Show ("Transaction Complete");

    result
    Conclusion:
    Hope this helps,
    Happy Coding.

    WCF
    ← How to rotate buttons(button animation) using wpf xaml asp.net
    what is windows workflow foundation(wf)/wf simple overview/introduction asp.net c# →

    Learn Easily Using Video Tutorials


    How to choose the right Java IDE – explained Eclipse NetBeans BlueJ

    Developing/Creating/Performing/Configuring Java Applications Using Eclipse IDE

    Step By Step Guide for Download/Install Configure Eclipse IDE for Java

    Editing data with the GridView control Asp.Net C#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Best way to prepare asp.net Interview - Success Stories

    Download Important Questions and PPT's:

    Sql Server Important Questions Online free download

    Dotnet Important Questions Online free download

    Exploring Linq to Sql Process Flow

    Learn how to perform silverlight programming

    Learn OOPs concepts in better and well manner

    Learn Ajax in better and well manner

    Leave a comment

    2 Comments.

    1. Wordpress Themes July 24, 2010 at 6:43 am

      Amiable fill someone in on and this fill someone in on helped me alot in my college assignement. Say thank you you on your information.

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    *

    *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Trackbacks and Pingbacks:

    • How to do/perform/create transactions in wcf asp.net c# … » WB Tips - Pingback on 2010/07/18/ 18:55

    Enter your email address:

    Delivered by FeedBurner

    • Recent Posts

      • Bounty Huge Roll [Amazon Frustration-Free Packaging]
      • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
      • The Basic Overview of Windows Mobile Development Asp.Net C#
      • Overview of Sql server extended properties Asp.Net C#
      • How to Use Sql Server Extended properties using visual studio Asp.Net C#
    • Search by Tags!

      Application AspNet Basic between Black Bluetooth Build Business Collection Consultants Design Development Downloading effective Excel Experts Generics Implement Installing Interview Logic Management Microsoft Minutes Object Outlook Professional Programmer Programming Project Projects Questions Ready Select Server Services Silverlight Source Strings Studio Through using Visual Website Wordpress
    • Archives

      • August 2011
      • June 2011
      • May 2011
      • April 2011
      • March 2011
      • February 2011
      • December 2010
      • November 2010
      • October 2010
      • September 2010
      • August 2010
      • July 2010
      • June 2010
      • May 2010
      • April 2010
      • March 2010
      • February 2010
      • January 2010
      • December 2009
      • November 2009
      • October 2009
      • September 2009

    Copyright © 2012 NetProgrammingHelp.com

    Δ Top