大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> NET专区 -> 在Web Service中实现Transaction

在Web Service中实现Transaction

时间: 2021-07-31 作者:daque

在Web Service中实现Transaction.net framework为类,webform和webservice供给了工作处置功效。在保守的windows运用步调中,要写一个有工作处置功效的组件不只要写代码并且要在组件效劳中创造一个工作包。这就表示着在任何一台要处置这个工作的呆板上,你都不得不翻开mmc在com+运用步调节点下创造一个新包。.net framework使得这十足变得很大略,究竟上咱们不必在组件效劳中作任何事,这十足都是机动实行的。对webservice来说,.net framework用enterprise services(com+的代替者)来处置工作,而无需创造一个com+包。一切处置工作状况的处事都是在幕后实行的。在webservice中实行这个很大略。1)在 [webmethod()]属性中指定transaction的典型。如[ webmethod ( false, transactionoption.requiresnew) ]以次是transactionoption的精细列表。transactionoption.disabledignoreany transaction in the current context. transactionoption.notsupportedcreatethe component in a context with no governing transaction. transactionoption.supportedsharea transaction if one exists; create a new transaction if necessary. transactionoption.requiredcreatethe component with a new transaction, regardless of the state of the current context. transactionoption.requiresnewsharea transaction if one exists. 2)用[autocomplete]属性保证transaction能实行,只有抛出特殊。由此咱们不妨看出在Web Service中实现Transaction的一点特出性,即transaction属性是运用于webmethod上的。这表示着在webservice中惟有树立了transactionoption后才会运用工作。提防:咱们不妨不要[autocomplete],本人写代码实行工作或遏止工作,例子如次try{ //update the balances: //if an account.balance goes below 0,  //an exception is thrown by the account object _credit.balance= _actdb.getbalance ( _credit.id ); _debit.balance= _actdb.getbalance ( _debit.id ); contextutil.setcommit;}//catch the exception from the account objectcatch ( exception ex ){ contextutil.setabort;}附上我的一段代码:using system;using system.collections;using system.componentmodel;using system.data;using system.diagnostics;using system.web;using system.web.services;using system.enterpriseservices;namespace michael.webservicetrans{public class financialutil : system.web.services.webservice{//create a class-level instance of the accountdb classmichael.data.accountdb _actdb = new michael.data.accountdb();[ webmethod ( false, transactionoption.requiresnew ) ][ autocomplete ]public decimal[] transfermoney ( decimal _amount, string _fromactnum, string _toactnum ){account _debit = new account ( _fromactnum );account _credit = new account ( _toactnum ); decimal[] _array = new decimal[2];_actdb.debitorcreditaccount ( true, _credit.id, _amount);_actdb.debitorcreditaccount ( false, _debit.id, _amount );try{_credit.balance= _actdb.getbalance ( _credit.id );_debit.balance= _actdb.getbalance ( _debit.id );}catch ( exception ex ){throw (new system.exception ( ex.message ) );}//return the new balances in the array_array[0] = _debit.balance;_array[1] = _credit.balance;return _array;}[webmethod()]public dataset getallaccountnumbers (){return _actdb.getallaccountnums();}//******************************************************////*********** visual studio designer code **************////******************************************************//public financialutil(){initializecomponent();}#region component designer generated code/// <summary>/// required method for designer support - do not modify/// the contents of this method with the code editor./// </summary>private void initializecomponent(){}#endregionprotected override void dispose( bool disposing ){}}}

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.