WCF分布式开发常见错误(14):无效的操作异常,At least one operation on the ...
2009-05-30 23:19
399 查看
Posted on 2009-05-30 23:41 Frank Xu Lei 阅读(375) 评论(2) 编辑 收藏 网摘 所属分类: WCF分布式开发常见错误
WCF事务编程过程中,会出现这个操作无效异常。信息如下:
At least one operation on the 'WCFServiceTransaction1' contract is configured with the TransactionFlowAttribute attribute set to Mandatory but the channel's binding 'NetTcpBinding' is not configured with a TransactionFlowBindingElement. The TransactionFlowAttribute attribute set to Mandatory cannot be used without a TransactionFlowBindingElement.
异常界面如图:
[align=left]我是在调试客户端事务模式的时候出现的错误,服务契约和服务类的代码如下:[/align]
[align=left] [/align]
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;
//ServiceContract 属性以及 Indigo 使用的所有其他属性均在 System.ServiceModel 命名空间中定义,
//因此本例开头使用 using 语句来引用该命名空间。
namespace WCFService
{
//1.服务契约
[ServiceContract(Namespace = "http://www.cnblogs.com/frank_xl/")]
public interface IWCFServiceTransaction1
{
//操作契约
[OperationContract]
//强制事务流,使用客户端事务
//[TransactionFlow(TransactionFlowAttribute
[TransactionFlow(TransactionFlowOption.Mandatory)]
bool AddNewData(string name);
}
//2.服务类,实现契约
//事务有10分钟的超时限制
//[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true, TransactionTimeout = "00:30:00")]
public class WCFServiceTransaction1 : IWCFServiceTransaction1
{
//实现接口定义的方法
//需要事务环境,启动事务
[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.TransactionInformation.CreationTime);
Console.WriteLine("WCFService 1 Transaction Status is {0}", System.Transactions.Transaction.Current.TransactionInformation.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.Transaction.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;
}
}
}
[align=left]我查阅到的资料:
1.http://social.msdn.microsoft.com/Forums/en-US/windowstransactionsprogramming/thread/d3020922-92b3-4dc5-ab22-b8fe34cbf40e;这个是属性没定义在操作契约上。
2.http://blogs.msdn.com/thelever/archive/2007/03/29/configuration-of-transactions-of-use-in-wcf.aspx;这个建议更换[TransactionFlow(TransactionFlowOption.Allowed)].
可以解决问题。但是我不能这样。
我这里是为了测试客户端事务模式写的代码。
所以大家都什么好的解决办法~谢谢[/align]
[align=left]3.已经找到解决办法:[/align]
[align=left]使用配置文件方式:[/align]
[align=left]添加一个绑定协议节点,。也可以使用编程方式。这里给出代码:[/align]
<bindings>
<netTcpBinding >
<binding name="netTcpBindingTcp" transactionFlow="true" transactionProtocol="WSAtomicTransactionOctober2004" >
<!--<reliableSession enabled="true" ordered="true"/>
<security mode="None"></security>-->
</binding>
</netTcpBinding>
</bindings>
[align=left]然后在服务终结点里使用这个配置:[/align]
<endpoint
address="net.tcp://localhost:9002/WCFServiceTransaction2"
bindingConfiguration="netTcpBindingTcp"
binding="netTcpBinding"
contract="WCFService.IWCFServiceTransaction2">
</endpoint>
【老徐的博客】
【作者】:Frank Xu Lei
【地址】:http://www.cnblogs.com/frank_xl/archive/2009/05/30/1492513.html
WCF事务编程过程中,会出现这个操作无效异常。信息如下:
At least one operation on the 'WCFServiceTransaction1' contract is configured with the TransactionFlowAttribute attribute set to Mandatory but the channel's binding 'NetTcpBinding' is not configured with a TransactionFlowBindingElement. The TransactionFlowAttribute attribute set to Mandatory cannot be used without a TransactionFlowBindingElement.
异常界面如图:
[align=left]我是在调试客户端事务模式的时候出现的错误,服务契约和服务类的代码如下:[/align]
[align=left] [/align]
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;
//ServiceContract 属性以及 Indigo 使用的所有其他属性均在 System.ServiceModel 命名空间中定义,
//因此本例开头使用 using 语句来引用该命名空间。
namespace WCFService
{
//1.服务契约
[ServiceContract(Namespace = "http://www.cnblogs.com/frank_xl/")]
public interface IWCFServiceTransaction1
{
//操作契约
[OperationContract]
//强制事务流,使用客户端事务
//[TransactionFlow(TransactionFlowAttribute
[TransactionFlow(TransactionFlowOption.Mandatory)]
bool AddNewData(string name);
}
//2.服务类,实现契约
//事务有10分钟的超时限制
//[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true, TransactionTimeout = "00:30:00")]
public class WCFServiceTransaction1 : IWCFServiceTransaction1
{
//实现接口定义的方法
//需要事务环境,启动事务
[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.TransactionInformation.CreationTime);
Console.WriteLine("WCFService 1 Transaction Status is {0}", System.Transactions.Transaction.Current.TransactionInformation.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.Transaction.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;
}
}
}
[align=left]我查阅到的资料:
1.http://social.msdn.microsoft.com/Forums/en-US/windowstransactionsprogramming/thread/d3020922-92b3-4dc5-ab22-b8fe34cbf40e;这个是属性没定义在操作契约上。
2.http://blogs.msdn.com/thelever/archive/2007/03/29/configuration-of-transactions-of-use-in-wcf.aspx;这个建议更换[TransactionFlow(TransactionFlowOption.Allowed)].
可以解决问题。但是我不能这样。
我这里是为了测试客户端事务模式写的代码。
所以大家都什么好的解决办法~谢谢[/align]
[align=left]3.已经找到解决办法:[/align]
[align=left]使用配置文件方式:[/align]
[align=left]添加一个绑定协议节点,。也可以使用编程方式。这里给出代码:[/align]
<bindings>
<netTcpBinding >
<binding name="netTcpBindingTcp" transactionFlow="true" transactionProtocol="WSAtomicTransactionOctober2004" >
<!--<reliableSession enabled="true" ordered="true"/>
<security mode="None"></security>-->
</binding>
</netTcpBinding>
</bindings>
[align=left]然后在服务终结点里使用这个配置:[/align]
<endpoint
address="net.tcp://localhost:9002/WCFServiceTransaction2"
bindingConfiguration="netTcpBindingTcp"
binding="netTcpBinding"
contract="WCFService.IWCFServiceTransaction2">
</endpoint>
【老徐的博客】
【作者】:Frank Xu Lei
【地址】:http://www.cnblogs.com/frank_xl/archive/2009/05/30/1492513.html
相关文章推荐
- WCF分布式开发常见错误(14):无效的操作异常,At least one operation on the ...
- WCF分布式开发常见错误解决(7):System.InvalidOperationException,Cannot have two operations in the same contract
- WCF分布式开发常见错误(10):套接字连接中断,The socket connection was aborted
- ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s) for this operation
- WCF分布式开发常见错误(15):Communication with the underlying transaction manager has failed.
- 启动Tomcat异常(Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of )
- 普通用户操作tomcat项目时报:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program
- Access denied; you need (at least one of) the RELOAD privilege(s) for this operation
- WCF分布式开发常见错误(19):There was an error opening the queue打开消息队列出错
- 线程使用中常见的错误-“System.InvalidOperationException”线程间操作无效: 从不是创建控件“ ”的线程访问它。
- WCF分布式开发常见错误(11):There is already a listener on IP endpoint ,IP 终结点 已经存在侦听器,
- WCF分布式开发常见错误(24):the SSL/TLS secure channel with authority
- mysql:Access denied; you need (at least one of) the RELOAD privilege(s) for this operation
- WCF分布式开发常见错误(4):The type or namespace name 'DataContract' could not be found DataContract找不到
- WCF分布式开发常见错误(19):There was an error opening the queue打开消息队列出错
- WCF分布式开发常见错误(16):The Transaction has aborted,事务已经被中断
- WCF分布式开发常见错误(24):Could not establish trust relationship for the SSL/TLS secure channel with authority
- Microsoft eMbedded Visual C++ has discovered no CE platform SDK installed on the desktop please install at least one CE platform
- WCF分布式开发常见错误(16):The Transaction has aborted,事务已经被中断
- xcode4.3发布报错 At least one of the following architecture(s) must be present: armv6 (-19033) 错误解决方法