开发者

How to roll back used functions in a web service? should I use transaction?

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
}

My web application receives required information which is filled by user and th开发者_StackOverflow中文版e first calls the RegisterWorker function and then calls the InsertWorkerInformation function.

int code=RegisterWorker(parameters)
InsertWorkerInformation(code)

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?


Generally, you don't. A normal webservice is a type of disconnected model. There's no transactions around multiple webservice calls.

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.

Alternatively, is there an 'UnRegisterWorker'? If so, that could be in your catch block to 'fake' a rollback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜