如何回滚Web服务中使用的功能?我应该使用交易吗?
我正在开发连接到Web服务的Web应用程序.Web服务为我提供了两个单独的功能,但它们彼此相关. RegisterWorker
函数注册一个工作人员并为其生成代码. InsertWorkerInformation
函数,根据生成的代码在数据库中插入一些辅助信息.
I'm developing a web application that connects to a web service.
web service gives me two separate functions but they are related each other.
RegisterWorker
function register a worker and generate a code for him/her.
InsertWorkerInformation
function, Inserts some worker information in data base according to generated code.
function int RegisterWorker(parameters)
{
return Genereated worker code;
}
function int InsertWorkerInformation(int generated worker code)
{
return 1;//If Success Insert information in DB
return 0;//If fails
}
我的Web应用程序收到用户填写的必需信息,并且第一个调用 RegisterWorker
函数,然后调用 InsertWorkerInformation
函数.
My web application receives required information which is filled by user and the first calls the RegisterWorker
function and then calls the InsertWorkerInformation
function.
int code=RegisterWorker(parameters)
InsertWorkerInformation(code)
第二个功能绝对必须在第一个功能之后运行.我想知道如果第一个功能正确执行但第二个功能无法正确执行该怎么办(可能会失去Web应用程序与Web Service等之间的连接)我该如何回滚第一个功能?
the second function absolutely must run after first function. I want to know what can I do if the first function executes properly but the second function doesn't execute properly.(maybe losing connection between web application and web service and etc) how can I roll back the first function?
通常,您不需要.普通的Web服务是一种断开连接的模型.多个Web服务调用之间没有事务.
Generally, you don't. A normal webservice is a type of disconnected model. There's no transactions around multiple webservice calls.
如果您有权访问此Web服务的代码,则可以创建一个在一次调用中执行两项操作并内部使用事务的Web方法.
If you have access to the code of this webservice, it may make sense to create a web method that performs both actions in one call, and it internally uses a transaction.
或者,是否有一个"UnRegisterWorker"?如果是这样,那可能在您的catch块中以伪造"回滚.
Alternatively, is there an 'UnRegisterWorker'? If so, that could be in your catch block to 'fake' a rollback.