支持XML Web服務的事務利用公共語言運行期中的支持
WebMethod屬性的TransactionOption屬性規定一個XML Web服務方法如何參與一個事務
XML Web服務方法只能參與一個作為新事務的根的事務
使用來自XML Web服務方法的事務
聲明一個XML Web服務
[C#]
<%@ WebService Language=
[Visual Basic]
<%@ WebService Language=
把一個匯編指令加到System
<%@ Assembly name=
添加引用到System
[C#]
using System
using System
[Visual Basic]
Imports System
Imports System
聲明一個XML Web服務方法
[C#]
[ WebMethod(TransactionOption=TransactionOption
public int DeleteAuthor(string lastName)
[Visual Basic]
< WebMethod(TransactionOption:=TransactionOption
Public Function DeleteAuthor(lastName As String) As Integer
下面的代碼示例顯示一個使用單個XML Web服務方法的XML Web服務
[C#]
<%@ WebService Language=
<%@ Assembly name=
using System;
using System
using System
using System
using System
public class Orders : WebService
{
[ WebMethod(TransactionOption=TransactionOption
public int DeleteAuthor(string lastName)
{
String deleteCmd =
lastName +
String exceptionCausingCmdSQL =
au_lname=
SqlConnection sqlConn = new SqlConnection(
SqlCommand deleteCmd = new SqlCommand(deleteCmdSQL
SqlCommand exceptionCausingCmd = new
SqlCommand(exceptionCausingCmdSQL
// This command should execute properly
deleteCmd
deleteCmd
// This command results in an exception
// automatically rolled back
// participating in a transaction
// automatically aborts the transaction
// executed properly is rolled back
int cmdResult = exceptionCausingCmd
sqlConn
return cmdResult;
}
}
[Visual Basic]
<%@ WebService Language=
<%@ assembly name=
Imports System
Imports System
Imports System
Imports System
Imports System
Imports System
Public Class Orders
<WebMethod(TransactionOption:=TransactionOption
Public Function DeleteAuthor (lastName as String) as Integer
Dim deleteCmdSQL As String =
lastName +
Dim exceptionCausingCmdSQL As String =
Dim sqlConn As SqlConnection = New SqlConnection( _
Dim deleteCmd As SqlCommand = New SqlCommand(deleteCmdSQL
Dim exceptionCausingCmd As SqlCommand = New _
SqlCommand(exceptionCausingCmdSQL
deleteCmd
deleteCmd
Dim cmdResult As Integer = exceptionCausingCmd
sqlConn
Return cmdResult
End Function
End Class
From:http://tw.wingwit.com/Article/program/net/201311/11378.html