I am facing strange issue with our WCF service. The same code was working fine until recently we added more OperationContracts(Web Methods).
We have common 3 tier architecture.
- DAL (WCF)
- BLL
- Web UI
Here is my quick sample code:
DAL (WCF):
[ServiceContract]
interface IPerson
{
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
int AddPerson(Person p);
}
// AddPerson is implemented in the service
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public int AddPerson(Person p)
{
// LINQ DataContext stuff goes here
}
BLL:
public class EmployeeBLL
{
public void AddNewEmployee(Person p)
{
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
try
{
PersonClient perClient = new PersonClient();
int personId = perClient.AddPerson(p);
ts.Complete();
}
catch (Exception ex)
{
// Log exception
}
finally
{
ts.Dispose();
}
}
perClient.Close();
}
}
Usage in Web UI:
EmployeeBLL empBLL = new EmployeeBLL ()
empBLL.AddNewEmployee(person);
I get "The service operation requires a transaction to be flowed." in my BLL when trying to call AddPerson method in service. Not much luck after enabling tracing in web.config.
Detailed Stack Trace:
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
Client Configuration:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IEmployee" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="true" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="5000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:2882/Test.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEmployee"
contract="Test.IEmployee" name="WSHttpBinding_IEmployee">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>