I have override Save() method of every entity in my BusinessObject, to save entity into database via webservice. Both the Webservice and the Client of it refrence to my BusinessObject. when I call Save() of entity, calling to webservice is transparent .
The overrided Save() method:
Code:
public override void Save()
{
System.Reflection.Assembly asm = Assembly.GetEntryAssembly();
if (asm != null) // run at server
{
Customer entity = WebServiceProxy.WsProxy.SaveEntity(this) as Customer;
this.PopulateEntity(entity.Table);
}
else //run at client
base.Save();
}
the WebServiceProxy.WsProxy.SaveEntity(this) Serialize this at first,then call the next SaveEntity webmethod.
My webmethod:
Code:
[WebMethod]
public byte[] SaveEntity(byte[] esEntityBinary)
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream(esEntityBinary);
esEntity entity = bf.Deserialize(ms) as esEntity;
entity.Save(esSqlAccessType.DynamicSQL);
ms = new MemoryStream();
bf.Serialize(ms, entity);
byte[] esEntitySavedBinary = ms.ToArray();
return esEntitySavedBinary;
}
When I run following code,the esTransactionScope can't rollback.
Code:
Customer newCustomer = new Customer();
newCustomer.AddNew();
newCustomer.CustomerName = "new customer";
using (EntitySpaces.Interfaces.esTransactionScope scope = new EntitySpaces.Interfaces.esTransactionScope())
{
newCustomer.Save();
CustomerDevelopement CurrentDevelopement = new CustomerDevelopement();
CurrentDevelopement.AddNew();
CurrentDevelopement.CustomerId = newCustomer.Id;
CurrentDevelopement.Save();
throw new Exception("Rollback!");
//scope.Complete();
}
In my solution , how to use esTransactionScope ?