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;
}
}
}