人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當(dāng)前位置:蘿卜系統(tǒng)下載站 > 技術(shù)開(kāi)發(fā)教程 > 詳細(xì)頁(yè)面

ASP.NET創(chuàng)建XML Web服務(wù)全接觸(13)

ASP.NET創(chuàng)建XML Web服務(wù)全接觸(13)

更新時(shí)間:2022-09-02 文章作者:未知 信息來(lái)源:網(wǎng)絡(luò) 閱讀次數(shù):

使用事務(wù)

    

 支持XML Web服務(wù)的事務(wù)利用公共語(yǔ)言運(yùn)行期中的支持,其是基于Microsoft Transaction Server ( MTS)和COM+ Services中相同的分布式事務(wù)模型。該模型基于明確的判斷一個(gè)對(duì)象是否參與一個(gè)事務(wù),而不是編寫(xiě)特定的代碼用來(lái)處理委托和回調(diào)一個(gè)事務(wù)。對(duì)于一個(gè)使用ASP.NET創(chuàng)建的XML Web服務(wù),你可以通過(guò)設(shè)置其應(yīng)用到一個(gè)XML Web服務(wù)方法上的WebMethod屬性的TransactionOption屬性來(lái)聲明一個(gè)XML Web服務(wù)的事務(wù)行為。如果該XML Web服務(wù)方法執(zhí)行的時(shí)候拋出一個(gè)異常,那么該事務(wù)自動(dòng)地結(jié)束;相反,如果沒(méi)有發(fā)生異常,該事務(wù)自動(dòng)委托。

  WebMethod屬性的TransactionOption屬性規(guī)定一個(gè)XML Web服務(wù)方法如何參與一個(gè)事務(wù)。雖然這個(gè)聲明級(jí)別表示一個(gè)事務(wù)邏輯,但是它是消除實(shí)際事務(wù)的一個(gè)步驟。當(dāng)事物對(duì)象訪問(wèn)數(shù)據(jù)源(如數(shù)據(jù)庫(kù)或消息隊(duì)列)時(shí)實(shí)際事務(wù)產(chǎn)生。關(guān)聯(lián)該對(duì)象的事務(wù)自動(dòng)流向適當(dāng)?shù)馁Y源管理程序。像.NET Framework Data Provider(用于SQL Server或OLE DB)這樣的.NET Framework數(shù)據(jù)提供者在對(duì)象的上下文中查找事務(wù)并通過(guò)Distributed Transaction Coordinator (DTC,分布式事務(wù)協(xié)調(diào)程序)編目事務(wù)。全部的事務(wù)自動(dòng)產(chǎn)生。

  XML Web服務(wù)方法只能參與一個(gè)作為新事務(wù)的根的事務(wù)。作為一個(gè)新事務(wù)的根,所有的與資源管理器(像運(yùn)行Microsoft SQL Server、Microsoft Message Queuing和Microsoft Host Integration Server的服務(wù)器)的相互作用維護(hù)需要運(yùn)行健壯的分布式應(yīng)用程序的ACID性質(zhì)。調(diào)用其他的XML Web服務(wù)方法的XML Web服務(wù)方法參與不同的事務(wù),因?yàn)槭聞?wù)不流經(jīng)XML Web服務(wù)方法。

  使用來(lái)自XML Web服務(wù)方法的事務(wù)

  聲明一個(gè)XML Web服務(wù)。

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


  把一個(gè)匯編指令加到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


  聲明一個(gè)XML Web服務(wù)方法,設(shè)置WebMethod屬性的TransactionOption屬性為T(mén)ransactionOption.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


  下面的代碼示例顯示一個(gè)使用單個(gè)XML Web服務(wù)方法的XML Web服務(wù),調(diào)用DeleteDatabase。這個(gè)XML Web服務(wù)方法執(zhí)行一個(gè)事務(wù)范圍內(nèi)的數(shù)據(jù)庫(kù)操作。如果該數(shù)據(jù)庫(kù)操作拋出一個(gè)異常,該事務(wù)自動(dòng)地停止;否則,該事務(wù)自動(dòng)地委托。

[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

 

 


溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

本類(lèi)教程下載

系統(tǒng)下載排行

網(wǎng)站地圖xml | 網(wǎng)站地圖html
主站蜘蛛池模板: 三穗县| 方城县| 晋城| 杭锦后旗| 安达市| 嘉峪关市| 多伦县| 社会| 宿州市| 英吉沙县| 龙游县| 革吉县| 巴彦淖尔市| 焦作市| 信阳市| 汽车| 历史| 丰顺县| 太保市| 区。| 瑞丽市| 西华县| 马鞍山市| 松江区| 正宁县| 瑞昌市| 南涧| 拉孜县| 平顶山市| 江达县| 昆山市| 怀远县| 潮安县| 临夏市| 高密市| 府谷县| 南岸区| 扎鲁特旗| 清镇市| 陆河县| 丘北县|