Hi Hugo,
Yes, to do this you would have to write something that would wrap the webservice calls. There are a few ways to do this, and you would also have to write a few lines of custom logic in the webservice template because it currently passes null.
We already include an HTTPModule which does just allows you to create the transactions for every request. You would just have to configure this in your web.config.
36 <httpModules>
37 <add name="EntityTransactionModule" type="NameSpace.Web.Data.EntityTransactionModule"/>
38 </httpModules>
WebService.cst
Then in your template, on every request into the DataRepository, you would add the ability to get the transaction. So it would be like:
FROM:
[WebMethod(Description="Inserts a row in the table <%=SourceTable.Name%>.")]
public <%=className%> <%=providerName%>_<%= MethodNames.Insert %>(<%=className%> entity )
{
<%=DALNameSpace%>.DataRepository.<%=providerName%>.<%= MethodNames.Insert %>(entity);
return entity;
}
TO:
[WebMethod(Description="Inserts a row in the table <%=SourceTable.Name%>.")]
public <%=className%> <%=providerName%>_<%= MethodNames.Insert %>(<%=className%> entity )
{
TransactionManager tm;
try
{
using (tm = EntityTransactionModule.TransactionManager)
{
if(!entity.IsValid)
{
entity.Tag = enity.Error;
return entity;
}
<%=DALNameSpace%>.DataRepository.<%=providerName%>.<%= MethodNames.Insert %>(tm, entity);
tm.Commit();
}
}
catch(Exception exc)
{
//you can use the Tag property to send messages, or the Error property will be filled of errors if the entity is not valid.
entity.Tag = exc.Message;
}
return entity;
}
//The end request of the http module will handle any cleanup and commits or rollbacks or you can set them explicity. The way i did it above, the dispose method will rollback if the tran is still open and it never reached the Commit(); If an exception is thrown, then mark the error and return.
Robert Hinojosa
-------------------------------------
Member of the Codesmith Tools, .netTiers, teams
http://www.nettiers.com-------------------------------------