WCF Distributed Development Common error (14): Invalid operation exception, at least one operation on the.

Source: Internet
Author: User
Tags bool

An invalid exception occurs during WCF transaction programming. The information is as follows:

At least one operation on the ' WCFServiceTransaction1 ' contract are configured with the Transactionflowattribute attribute The set to mandatory but the channel ' s binding ' nettcpbinding ' isn't configured with a transactionflowbindingelement. The Transactionflowattribute set to mandatory cannot is used without a transactionflowbindingelement.

The exception interface is shown in figure:

I was in the debugging client transaction mode when the error occurred, the service contract and the service class code is as follows:

using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


using System.ServiceModel;


using System.Runtime.Serialization;


using System.Transactions;


using System.Diagnostics;

The
//servicecontract property and all other properties used by Indigo are defined in the System.ServiceModel namespace.


//So this example starts with a using statement to refer to the namespace.





namespace Wcfservice


{


//1. Service Contract


[ServiceContract (Namespace = "http://www.cnblogs.com/frank_xl/")]


public Interface IWCFServiceTransaction1


     {


//Operation contract


[OperationContract]


//Force transaction flow, using client transaction


//[transactionflow (Transactionflowattribute


[TransactionFlow (transactionflowoption.mandatory)]


bool Addnewdata (string name);





     }


//2. Service class, implement contract


//transaction has a timeout limit of 10 minutes


//[servicebehavior (Includeexceptiondetailinfaults = true)]


[ServiceBehavior (Includeexceptiondetailinfaults = true, TransactionTimeout = "00:30:00")]


public class Wcfservicetransaction1:iwcfservicetransaction1


     {


//Implementation of the interface definition method


//Need transaction environment, start transaction


[OperationBehavior (transactionscoperequired = true, TransactionAutoComplete = True)]


public bool Addnewdata (string name)


         {


Transaction Transaction = transaction.current;


Debug.Assert (System.transactions.transaction.current.transactioninformation.distributedidentifier!=guid . Empty);


Console.WriteLine ("Create a new Transaction at {0}", System.Transactions.Transaction.Current.Transactio Ninformation.creationtime);


Console.WriteLine ("Wcfservice 1 Transaction Status is {0}", System.Transactions.Transaction.Current.Tra Nsactioninformation.status);


Console.WriteLine ("Wcfservice 1 Transaction localidentifier is {0}", System.Transactions.Transaction.Current.TransactionInformation.LocalIdentifier);


Console.WriteLine ("Wcfservice 1 Transaction distributedidentifier is {0}", System.Transactions.Transact Ion. Current.TransactionInformation.DistributedIdentifier);





//using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope ())


             //{


Try


             {


using (usertableadapter adapter = new Usertableadapter ())


                 {


if (1 = adapter. CreateUser (name))


                     {


Console.WriteLine ("Calling WCF Transaction sucessfully name Length is:{0} ", name. Length);


                     }


Else


                     {


Console.WriteLine ("Calling WCF Transaction unsucessfully name length is : {0} ", name. Length);


//return false;


                     }


                 }


             }


catch (Exception e)


             {


Console.WriteLine ("Calling WCF Transaction error:{0}", E.message);


throw E;


//return false;


}





//ts.complete ();


return true;





         }


     }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.