Description="Hello Ansel,This is a testing Web Service!")]
public class AttributeTest : System.Web.Services.WebService
{
[WebMethodAttribute(Description="描述資訊:繼承了Count方法,並且對名稱進行重載。執行的是把錢從A使用者轉帳到B使用者......",
//MessageName="Changing MessageName",
BufferResponse=true,
CacheDuration=1000,
EnableSession=true,
TransactionOption=TransactionOption.RequiresNew)]
public string transMoney(double Money)
{
try
{
ContextUtil.EnableCommit();//Transaction only used to Database operation!
MoneyInToA(Money);
MoneyOutFromB(Money);
ContextUtil.SetComplete();
return "Transaction Successful,total "+Money.ToString();
}
catch( Exception e)
{
ContextUtil.SetAbort();
return "Transaction failed! \n\r "+e.Message;
}
}
private void MoneyInToA(double Money)
{
SqlCommand sqlCom = new SqlCommand("update budget set Money=Money+"+Money.ToString()+" where Name='A'");
databaseAccess myDatabase = new databaseAccess();
sqlCom.Connection=myDatabase.getConnection();
sqlCom.Connection.Open();
sqlCom.ExecuteNonQuery();
sqlCom.Connection.Close();
//throw new Exception("Operation failed when transfer money into A!");
}
private void MoneyOutFromB(double Money)
{
SqlCommand sqlCom = new SqlCommand("update budget set Money=Money-"+Money.ToString()+" where Name='B'");
databaseAccess myDatabase = new databaseAccess();
sqlCom.Connection=myDatabase.getConnection();
sqlCom.Connection.Open();
sqlCom.ExecuteNonQuery();
sqlCom.Connection.Close();
//throw new Exception("Operation failed when transfer money from B!");
}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
aa:AttributeTestSoap;//這個就是WSDL下的類介面對象
msg:widestring;
bb:double;
begin
//HTTPRIO2 其實就是所謂的代理類,它負責進行資料轉送發送Request和接受Response的
aa:=HTTPRIO2 as AttributeTestSoap;