פורסם 2012 באפריל 2313 שנים העלתי את הבעיה שלי ל http://stackoverflow.com/questions/10270729/wcf-transactionscope-doesnt-rollback#עזרתם לי הרבה בפעמים הקודמות אז למה לא להמשיך לאתגר אותכם.וחשבתי שאולי תוכלו לתת לי עצה או פתרון במקביל וגם למה לא אם הוא בעברית !I have a service and client Application and I dont have a clue what is the problem with this code. after doing this line perfectly and save it in my DB,proxy.AddEmployee("Stav", "20");the next line throw Exception becouse I didnt send a number to the Age parameter, but the Transaction doesnt RollBack the first line so the Information : Stav, 20 still exsist in my DB!proxy.AddEmployee("Stav123", "Not a Number(-->will do Exception)") client:static void Main(string[] args) { ServiceReference1.IJob proxy = new ServiceReference1.JobClient(); using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { try { proxy.AddEmployee("Stav", "20"); proxy.AddEmployee("Stav123", "Not a Number(-->will do Exception) ");//stop the running and show the Exception but keep the stav,20 in DB ts.Complete(); } catch { ts.Dispose(); } } }service:[ServiceContract] public interface IJob { [OperationContract] [TransactionFlow(TransactionFlowOption.Allowed)] void AddEmployee(string Name, string Age); }public class JobImplement:IJob { [OperationBehavior(TransactionScopeRequired = true)] public void AddEmployee(string Name, string Age) {string strConnection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\stavalfi\Desktop\WCF2\ConsoleApplication4\WCF_DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; SqlConnection objConnection = new SqlConnection(strConnection); objConnection.Open(); SqlCommand objCommand = new SqlCommand("INSERT INTO Employee (Name,Age) " + "VALUES ('" + Name + "' ,'" + Age + "')", objConnection); objCommand.ExecuteNonQuery(); objConnection.Close(); } }static void Main(string[] args) { WSHttpBinding Basic = new WSHttpBinding(); Basic.TransactionFlow = true; ServiceHost host = new ServiceHost(typeof(JobImplement), new Uri("[url]http://localhost:8080"[/url])); // ServiceMetadataBehavior behavior = new ServiceMetadataBehavior(); behavior.HttpGetEnabled = true; host.Description.Behaviors.Add(behavior); // host.AddServiceEndpoint(typeof(IJob), new BasicHttpBinding(), "Request123"); host.Open(); // Console.WriteLine("opened"); Console.ReadLine(); // host.Close(); }עריכה : נפתר host.AddServiceEndpoint(typeof(IJob), new BasicHttpBinding(), "Request123");הגדרתי את החיבור למעלה שאני רוצה להשתמש בו ולא השתמשתי בו.. טעות מפגרת חח
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.