WCF

WCF Examples

WCF

WCF Projects

WCF Project

adplus-dvertising
Requiring transaction flow
Previous Home Next

The Client/Service mode requires the use of a transaction-aware binding with transaction flow enabled, and yet this is not enforced by WCF at the service load time

[AttributeUsage(AttributeTargets.Class)]
public class BindingRequirementAttribute : Attribute,IServiceBehavior
{
public bool TransactionFlowEnabled //Default is false
{get;set;}
//More members
}

The BindingRequirementAttribute:

[AttributeUsage(AttributeTargets.Class)]
public class BindingRequirementAttribute : Attribute,IServiceBehavior
{
public bool TFEnabled
{get;set;}
void IServiceBehavior.Validate(ServiceDescription description,
 ServiceHostBase host)
{
if(TFEnabled == false)
{
return;
}
foreach(ServiceEndpoint endpoint in description.Endpoints)
{
Exception exception = new InvalidOperationException(...);

foreach(OperationDescription operation in endpoint.Contract.Operations)
{
foreach(IOperationBehavior behavior in operation.Behaviors)
{
if(behavior is TransactionFlowAttribute)
{
TransactionFlowAttribute  TFattribute =
 behavior as TransactionFlowTFattribute;
if(TFattribute.Transactions == TransactionFlowOption.Allowed)
{
if(endpoint.Binding is NetTcpBinding)
{
NetTcpBinding tcpBinding =
 endpoint.Binding as NetTcpBinding;
if(tcpBinding.TransactionFlow == false)
{
throw exception;
}
break;
}
...  //Similar checks for the rest of the transaction-aware
  //bindings

throw new InvalidOperationException(...);
}
}
}
}
}
}
void IServiceBehavior.AddBindingParameters(...)
{}
void IServiceBehavior.ApplyDispatchBehavior(...)
{}
}
Previous Home Next