The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

esTransactionScope do not work via Webservice

Last post 07-07-2007, 7:54 PM by jtpdotnet. 4 replies.
Sort Posts: Previous Next
  •  07-07-2007, 6:29 PM 3693

    esTransactionScope do not work via Webservice

    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(thisSerialize 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 ?

  •  07-07-2007, 6:35 PM 3694 in reply to 3693

    Re: esTransactionScope do not work via Webservice

    If you are in a using(esTransactionScope) section and exit without calling Scope.Complete() the transaction will not complete, it will in effect be rolled back. There is no rollback method nor is there one on the Microsoft TransactionScope. Does this answer your question?

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  07-07-2007, 7:22 PM 3695 in reply to 3694

    Re: esTransactionScope do not work via Webservice

    Thanks for your reply.

    I have test, when I do not use webservice , calling to base.Save() directly is OK, it rolled back.

    when I use webservice in above way,it do not rolled back, a new customer record has been created in database.

    My question is how to roll back via webservice in above way?

  •  07-07-2007, 7:29 PM 3696 in reply to 3695

    Re: esTransactionScope do not work via Webservice

    You cannot use transactions on the client side of a webservice with any architecture really? The sql connections and transactions all live on the server side.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  07-07-2007, 7:54 PM 3697 in reply to 3696

    Re: esTransactionScope do not work via Webservice

    I have see, thank you Mike.

    Does cannot use entity.AssociateXXXCollection() in Many to Many on the client side of a webservice ?

    I have just test. it do not work on the client side of a webservice , without any Exception.

    when I use entity.AssociateXXXCollection() and entity.Save() not via webservie , it work well.

View as RSS news feed in XML