HOW TO:在使用 ASP.NET 建立的 Web 服務中參與交易
本主題專門說明舊有技術。 應該使用下列建立 XML Web Service 及 XML Web Service 用戶端: Windows Communication Foundation.
程式碼範例
對於使用 ASP.NET 建立的 XML Web Service,您可以在套用至 Web 服務方法的 WebMethod 屬性 (Attribute) 上,設定 TransactionOption 屬性 (Property),來宣告 Web 服務的交易行為。如需 Web 服務方法中交易運作方式的說明,請參閱 ASP.NET XML Web Service 中的交易。
若要從 Web 服務方法參與交易
宣告 Web 服務。
<%@ WebService Language="C#" Class="Orders" %>
<%@ WebService Language="VB" Class="Orders" %>
將 Assembly 指示詞加入至 System.EnterpriseServices。
<%@ Assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %>
加入 System.Web.Services 和 System.EnterpriseServices 命名空間的參考。
using System.Web.Services; using System.EnterpriseServices;
Imports System.Web.Services Imports System.EnterpriseServices
宣告 Web 服務方法,並將 WebMethodAttribute 屬性 (Attribute) 的 TransactionOption 屬性 (Property) 設定為 System.EnterpriseServices.TransactionOption.RequiresNew。
[ WebMethod(TransactionOption=TransactionOption.RequiresNew)] public int DeleteAuthor(string lastName)
< WebMethod(TransactionOption:=TransactionOption.RequiresNew)> _ Public Function DeleteAuthor(lastName As String) As Integer
另請參閱
參考
TransactionOption Enumeration
WebMethodAttribute.TransactionOption Property