Web服务中的事务 [英] transaction in Web services

查看:79
本文介绍了Web服务中的事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Web服务中使用sql事务?

我创建了一个Web服务,该服务允许在远程服务器上执行sql语句.我创建了一个返回数据集的web方法.它的工作正常,但是当我将事务作为参数传递给方法时,它给了我错误,例如
"sqltransaction无法序列化,因为它没有无参数的构造函数"

How can I use sql transaction in a web service ?

I have created a webservice which allows to perform sql statements on remote server. I have created a webmethod which returns dataset. Its working fine but, when i pass transaction as parameter to the method, it gives me error such as,
"sqltransaction cannot be serialized as it does not have a parameterless constructor"
while executing the web service.

推荐答案

您不能将SQL事务传递给调用方.首先,不能保证该调用将了解有关.NET Framework的任何信息.其次,Web服务不维护与其客户端的连接,因此Web服务会话可能会超时而无需提交事务.

事务最好留给Web服务而不是Web服务客户端执行.
You cannot pass an SQL Transaction to the caller. First, there''s no guarantee that the call will know anything about the .NET Framework. Second, Web Services do not maintain connections to their clients, so a web service session can time out without the transaction being commited.

Transactions are best left to the operation being performed by the web service, not the web service client.


如果需要事务支持,您应该真正考虑使用WCF来管理事务本身,而不是尝试在调用代码中对其进行管理.我建议您阅读 [
If you need transaction support, you should really look at using WCF to manage the transaction itself, rather than you attempting to manage it in your calling code. I suggest that you read this[^] article to see how WCF can manage the transactions for you.


这篇关于Web服务中的事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆