I've figured out how to insert data into my database after i hit the submit button in my web application. However, I would have to declare a web method for inserting of data into the database in my web service application as well. Can anyone tell me how
to i declare the web method for inserting of data?
yes. i need to create a web method in the web service. I've read all these articles already. But they're to complicated for me to digest. :( I dun understand still.
I've tried out this codings. But i don't know if im doing the right thing. Could you check for me?
im still doing the codings on my Transaction.cs now. Then i can run to see if i get any errors. (: But im stuck again! The insert of data doesnt work, but the viewing of all transactions work fine.
To test the operation using the HTTP POST protocol, click the 'Invoke' button. <form action=http://localhost:3034/ProcessTransaction.asmx/insertDetails method=post target=_blank>
duckiieVON
Member
3 Points
37 Posts
How to declare a web method in aspx web service application to insert data into microsoft access
Jan 03, 2009 07:36 AM|LINK
I've figured out how to insert data into my database after i hit the submit button in my web application. However, I would have to declare a web method for inserting of data into the database in my web service application as well. Can anyone tell me how to i declare the web method for inserting of data?
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 11:13 AM|LINK
So you mean you need to create a WebMethod in a web service??
see here
http://aspalliance.com/979_Working_with_Web_Services_Using_ASPNET
http://msdn.microsoft.com/en-us/library/ms972326.aspx
http://www.codeproject.com/KB/webservices/aspwebsvr.aspx
Contact me
duckiieVON
Member
3 Points
37 Posts
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 12:15 PM|LINK
yes. i need to create a web method in the web service. I've read all these articles already. But they're to complicated for me to digest. :( I dun understand still.
I've tried out this codings. But i don't know if im doing the right thing. Could you check for me?
namespace BankWebServiceApp{
/// <summary> /// Summary description for Service1 /// </summary> [WebService(Namespace = "http://tempuri.org/")][
WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] public class ProcessTransaction : System.Web.Services.WebService{
//Create a new Transaction object Transaction transObj = new Transaction();[
WebMethod] public DataSet getAllTransactions(){
return transObj.getAllTransactions();}
[WebMethod]public DataSet insertBank(string BankAccountNumber, string Amount){
return transObj.insertBank(BankAccountNumber, Amount);}
}
}
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 12:21 PM|LINK
Yes it seems to be correct. Do you get any error??
Contact me
duckiieVON
Member
3 Points
37 Posts
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 12:32 PM|LINK
im still doing the codings on my Transaction.cs now. Then i can run to see if i get any errors. (: But im stuck again! The insert of data doesnt work, but the viewing of all transactions work fine.
<div class=e> <?xml version="1.0" encoding="utf-8" ?> </div> <div class=e> <div class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em">- <DataSet xmlns="http://tempuri.org/"></div> <div> <div class=e> <div class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em">- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"></div> <div> <div class=e> <div class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em">- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"></div> <div> <div class=e> <div class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em">- <xs:complexType></div> <div> <div class=e> <div style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <xs:choice minOccurs="0" maxOccurs="unbounded" /> </div></div> <div> </xs:complexType></div></div></div> <div> </xs:element></div></div></div> <div> </xs:schema></div></div></div> <div class=e> <div style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" /> </div></div> <div> </DataSet></div></div></div>This is the error i get. And below are my codings.
namespace BankWebServiceApp{
public class Transaction{
string errMsg; DBConnection dbCon = new DBConnection(); OleDbConnection conn = new OleDbConnection();public DataSet getAllTransactions(){
conn = dbCon.getConnection();
DataSet transData = new DataSet(); try{
conn.Open();
string sql = "SELECT * FROM Bank"; OleDbDataAdapter dbAdapter = new OleDbDataAdapter(sql, conn); dbAdapter.Fill(transData, "trans");conn.Close();
}
catch (Exception ex){
errMsg = ex.Message;
}
return transData;}
public DataSet insertbankDetails(String BankAccountNumber, string amount){
conn = dbCon.getConnection();
DataSet bankDetail = new DataSet(); try{
conn.Open();
string sql = "INSERT * INTO Bank where BankAccountNumber ='" + BankAccountNumber + "'"; OleDbDataAdapter dbAdapter = new OleDbDataAdapter(sql, conn); dbAdapter.Fill(bankDetail, "bankDetails");conn.Close();
}
catch (Exception ex){
errMsg = ex.Message;
}
return bankDetail;}
}
}
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 01:00 PM|LINK
use this for insert
public void insert(String strBankAccountNumber, String strAmount){
String strQuery = "INSERT INTO Bank (amount) values (@Amount) where BankAccountNumber = @BankAccountNumber"; OleDbCommand cmd = new OleDbCommand(strQuery, conn); cmd.Parameters.AddWithValue("@Amount", strAmount);cmd.Parameters.AddWithValue(
"@BankAccountNumber", strBankAccountNumber); cmd.CommandType = CommandType.Text; try{
conn.Open();
cmd.ExecuteNonQuery();
}
catch{
}
finally{
con.Close();
cmd.Dispose();
}
}
Contact me
duckiieVON
Member
3 Points
37 Posts
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 01:11 PM|LINK
insertDetails
Test
To test the operation using the HTTP POST protocol, click the 'Invoke' button. <form action=http://localhost:3034/ProcessTransaction.asmx/insertDetails method=post target=_blank>SOAP 1.1
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /ProcessTransaction.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/insertDetails" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <insertDetails xmlns="http://tempuri.org/"> <BankAccountNumber>string</BankAccountNumber> </insertDetails> </soap:Body> </soap:Envelope>HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <insertDetailsResponse xmlns="http://tempuri.org/"> <insertDetailsResult> <xsd:schema>schema</xsd:schema>xml</insertDetailsResult> </insertDetailsResponse> </soap:Body> </soap:Envelope>SOAP 1.2
The following is a sample SOAP 1.2 request and response. The placeholders shown need to be replaced with actual values.
POST /ProcessTransaction.asmx HTTP/1.1 Host: localhost Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <insertDetails xmlns="http://tempuri.org/"> <BankAccountNumber>string</BankAccountNumber> </insertDetails> </soap12:Body> </soap12:Envelope>HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <insertDetailsResponse xmlns="http://tempuri.org/"> <insertDetailsResult> <xsd:schema>schema</xsd:schema>xml</insertDetailsResult> </insertDetailsResponse> </soap12:Body> </soap12:Envelope>HTTP POST
The following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.
After i click the "Invoke" button. They showed me this error message.
<?xml version="1.0" encoding="utf-8" ?>
<div class=e> <div class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em">- <DataSet xmlns="http://tempuri.org/"></div> <div> <div class=e> <div class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em">- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"></div> <div> <div class=e> <div class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em">- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"></div> <div> <div class=e> <div class=c style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em">- <xs:complexType></div> <div> <div class=e> <div style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <xs:choice minOccurs="0" maxOccurs="unbounded" /> </div></div> <div> </xs:complexType></div></div></div> <div> </xs:element></div></div></div> <div> </xs:schema></div></div></div> <div class=e> <div style="MARGIN-LEFT: 1em; TEXT-INDENT: -2em"> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" /> </div></div> <div> </DataSet></div> <div> </div> <div> </div></div></div>mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 01:16 PM|LINK
This is not a error message this is the soap envelope
To use the method you will have to create an object of ur WebService and then call the insert method
Contact me
duckiieVON
Member
3 Points
37 Posts
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 01:21 PM|LINK
And also there is some error with the insert codings too. Below is the screenshot. "void" and "OleDbCommand" are triggered with the red line.
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to declare a web method in aspx web service application to insert data into microsoft acc...
Jan 03, 2009 01:29 PM|LINK
where you have placed the function ?? place it in class
Contact me