I haven't worked much with transaction scoping and I want to make sure that I'm approaching this idea correctly before I jump in too deeply.
The Setup / Goal
- I have a list of items that are files to be copied to a remote system.
- For each file in that list, I need to create a transaction to:
- Copy the file to a remote system
- Make a call to a web service to add a reference to that new file to a database.
- If either the web service call or the file copy fail, I need to roll both actions back.
- Rolling back the file copy will mean deleting the file on the remote system.
- Rolling back the web service action will mean calling a different web service method to delete the entry I just made.
- If any of the items in the list of items fail, I'd like to return a message of some kind, but not stop the other items from being committed.
What I'm Considering Doing
In my (quite limited) reading on the topic, I think this might be the proper approach:
- Create a Resource Manager for file copies that allows it to participate in durable transactions
- Create a Resource Manager for the web service call along the same lines
- Create a foreach loop for each item in the list
- For each item, create a transaction scope that uses the two resource managers and rolls back / reports if something goes wrong.
The Question(s)
- Is there anything I'm not seeing here or a new methodology I should be implementing, or is this actually the way to go?
Resources So Far
As I examine the problem and try to wrap my head around it, these are some of the pages I'm perusing:
- Implementing a Resource Manager [MSDN]
- Enlisting Resources as participants in a transaction [MSDN]
- Implementing an Implicit Transaction using TransactionScope [MSDN]
Thanks in advance for any help you can give!