Today, I have tested the WebService's business through and remote friends, unlocking my confusion, and further know how to apply it. As follows: [WebMethod (TransactionOption = TransactionOption.Requiresnew)] Public String Trans (Int threadsleep, int Money) {Try {// Implement an automatic thing --- contentil.enableCommit () in the database in the database CONTEXTUTIL.ENABLECMIT (). Subsql Server (Money); // Access SQLServer Database Thread.Sleep (ThreadsLeep); this.addsql Server (Money); // Access SQLServer Database ContextUtil.setComplete (); // If the deduction and plus Successful return "Transfer success! "} Catch (Exception E) {ContextUtil.Setabort (); // If an abnormality is rolling. Return "Transfer Failure:" E.MESSAGE.TOSTRING ();}} PUBLIC VOID SUBSQLSERVER (INT MONEY) {SQLCONNECTION CNN = New SqlConnection (@ "data source = bmonkey; uid = sa; pwd = 123; Initial Catalog = test "); cnn.open (); sqlcommand cmd = new sqlcommand (" Update Bank Set Money () "WHERE Userid = 'A'", CNN); cmd.executenonQuery () }
Catch (Exception E) {throw new exception ("localhostsql database operation failed ::" E.MESSAGE.TOSTRING ());}}