六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

ASP.NET創建Web服務之使用事務

[摘要]支持XML Web服務的事務利用公共語言運行期中的支持,其是基于Microsoft Transaction Server ( MTS)和COM+ Services中相同的分布式事務模型。該模型基于明確的判斷一個對象是否參與一個事務,而不是編寫特定的代碼用來處理委托和回調一個事務。對于一個使用ASP...

  支持XML Web服務的事務利用公共語言運行期中的支持,其是基于Microsoft Transaction Server ( MTS)和COM+ Services中相同的分布式事務模型。該模型基于明確的判斷一個對象是否參與一個事務,而不是編寫特定的代碼用來處理委托和回調一個事務。對于一個使用ASP.NET創建的XML Web服務,你可以通過設置其應用到一個XML Web服務方法上的WebMethod屬性的TransactionOption屬性來聲明一個XML Web服務的事務行為。如果該XML Web服務方法執行的時候拋出一個異常,那么該事務自動地結束;相反,如果沒有發生異常,該事務自動委托。

  WebMethod屬性的TransactionOption屬性規定一個XML Web服務方法如何參與一個事務。雖然這個聲明級別表示一個事務邏輯,但是它是消除實際事務的一個步驟。當事物對象訪問數據源(如數據庫或消息隊列)時實際事務產生。關聯該對象的事務自動流向適當的資源管理程序。像.NET Framework Data Provider(用于SQL Server或OLE DB)這樣的.NET Framework數據提供者在對象的上下文中查找事務并通過Distributed Transaction Coordinator (DTC,分布式事務協調程序)編目事務。全部的事務自動產生。

  XML Web服務方法只能參與一個作為新事務的根的事務。作為一個新事務的根,所有的與資源管理器(像運行Microsoft SQL Server、Microsoft Message Queuing和Microsoft Host Integration Server的服務器)的相互作用維護需要運行健壯的分布式應用程序的ACID性質。調用其他的XML Web服務方法的XML Web服務方法參與不同的事務,因為事務不流經XML Web服務方法。

  使用來自XML Web服務方法的事務

  聲明一個XML Web服務。

[C#]
<%@ WebService Language="C#" Class="Orders" %>
[Visual Basic]
<%@ WebService Language="VB" Class="Orders" %>

  把一個匯編指令加到System.EnterpriseServices上。

<%@ Assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %>

  添加引用到System.Web.Services和System.EnterpriseServices域名空間。

[C#]
using System.Web.Services;
using System.EnterpriseServices;
[Visual Basic]
Imports System.Web.Services
Imports System.EnterpriseServices

  聲明一個XML Web服務方法,設置WebMethod屬性的TransactionOption屬性為TransactionOption.RequiresNew。

[C#]
[ WebMethod(TransactionOption=TransactionOption.RequiresNew)]
public int DeleteAuthor(string lastName)
[Visual Basic]
< WebMethod(TransactionOption:=TransactionOption.RequiresNew)> _
Public Function DeleteAuthor(lastName As String) As Integer

  下面的代碼示例顯示一個使用單個XML Web服務方法的XML Web服務,調用DeleteDatabase。這個XML Web服務方法執行一個事務范圍內的數據庫操作。如果該數據庫操作拋出一個異常,該事務自動地停止;否則,該事務自動地委托。

[C#]
<%@ WebService Language="C#" Class="Orders" %>
<%@ Assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %>
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
using System.EnterpriseServices;

public class Orders : WebService
{
[ WebMethod(TransactionOption=TransactionOption.RequiresNew)]
public int DeleteAuthor(string lastName)
{
String deleteCmd = "DELETE FROM authors WHERE au_lname='" +
lastName + "'" ;
String exceptionCausingCmdSQL = "DELETE FROM NonExistingTable WHERE
au_lname='" + lastName + "'" ;

SqlConnection sqlConn = new SqlConnection(
"Persist Security Info=False;Integrated Security=SSPI;database=pubs;server=myserver");

SqlCommand deleteCmd = new SqlCommand(deleteCmdSQL,sqlConn);
SqlCommand exceptionCausingCmd = new
SqlCommand(exceptionCausingCmdSQL,sqlConn);

// This command should execute properly.
deleteCmd.Connection.Open();
deleteCmd.ExecuteNonQuery();

// This command results in an exception, so the first command is
// automatically rolled back. Since the XML Web service method is
// participating in a transaction, and an exception occurs, ASP.NET
// automatically aborts the transaction. The deleteCmd that
// executed properly is rolled back.

int cmdResult = exceptionCausingCmd.ExecuteNonQuery();

sqlConn.Close();

return cmdResult;
}
}
[Visual Basic]
<%@ WebService Language="VB" Class="Orders" %>
<%@ assembly name="System.EnterpriseServices" %>

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.Web.Util
Imports System.EnterpriseServices

Public Class Orders

<WebMethod(TransactionOption:=TransactionOption.RequiresNew)> _
Public Function DeleteAuthor (lastName as String) as Integer

Dim deleteCmdSQL As String = "DELETE FROM authors WHERE au_lname='" + _
lastName + "'"
Dim exceptionCausingCmdSQL As String = "DELETE FROM " + _
"NonExistingTable WHERE au_lname='" + lastName + "'"

Dim sqlConn As SqlConnection = New SqlConnection( _
"Persist Security Info=False;Integrated Security=SSPI;database=pubs;server=myserver")

Dim deleteCmd As SqlCommand = New SqlCommand(deleteCmdSQL,sqlConn)
Dim exceptionCausingCmd As SqlCommand = New _
SqlCommand(exceptionCausingCmdSQL,sqlConn)

' This command should execute properly.
deleteCmd.Connection.Open()
deleteCmd.ExecuteNonQuery()

' This command results in an exception, so the first command is
' automatically rolled back. Since the XML Web service method is
' participating in a transaction, and an exception occurs, ASP.NET
' automatically aborts the transaction. The deleteCmd that
' executed properly is rolled back.

Dim cmdResult As Integer = exceptionCausingCmd.ExecuteNonQuery()
sqlConn.Close()

Return cmdResult
End Function
End Class




主站蜘蛛池模板: 欧美一级做性受 | 天美传媒一区二区三区 | 欧美在线视频你懂的 | 婷婷丁香五月中文字幕 | 午夜影院美女 | 色资源网| 人妖欧美一区二区三区四区 | 亚洲国产中文字幕 | 一级做a爰片久久毛片下载 一级做a爰片久久毛片图片 | 中文天堂在线www | 日本香蕉一区二区三区 | 亚洲精品123区 | 四虎成人免费大片在线 | 亚洲fuli在线观看 | 青青草视频免费观看 | 日本免费三片在线播放 | 天天狠狠| 日韩高清在线免费观看 | 亚洲五月七月丁香缴情 | 全黄大片| 欧美在线观看a | 色久天| 日本欧美大片 | 亚色在线播放 | 四虎影永久在线高清免费 | 一二三四影视在线看片 | 五月天色婷婷丁香 | 欧美一级黄色录像 | 青娱乐在线视频盛宴 | 亚洲高清在线 | 午夜免费啪视频观看网站 | 日日噜噜夜夜狠狠久久丁香 | 亚洲国产99| 午夜污污 | 午夜精品aaa国产福利 | 天天弄天天干 | 涩涩欧美 | 色婷婷精品综合久久狠狠 | 亚洲第二色 | 香蕉狠狠再啪线视频 | 天天干亚洲|