Newbie Q: Return Error to Page?

S

Soul

Hi,

I have a web service method which will connect to a Access database, which
look like below:

[WebMethod(Description="Search database based on provided string.")]
public DataSet Search(string strSearch)
{
try
{
string strConnection = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source="
+ (string)Server.MapPath("../global_res/global_db.mdb");
string sqlStatement = "SELECT * FROM Contact ORDER BY ContactId";
this.oleDbConnection.ConnectionString = strConnection;
this.oleDbCommand.CommandText = sqlStatement;
this.oleDbCommand.Connection = this.oleDbConnection;
this.oleDbDataAdapter.SelectCommand = this.oleDbCommand;
this.oleDbConnection.Open();
this.oleDbDataAdapter.Fill(this.dataSet, "Contact");
this.oleDbConnection.Close();
this.FindStaff(strSearch);
return this.dataSet.Copy();
}
catch (Exception ex)
{
return ??????;
}
}

I am wondering if I put a try-catch statement in this method, how should I
return the error text to the page that request this web service method since
this method suppose to return DataSet but not string?

The aspx. page that request this web service method look something like:

CONTACTService cs = new CONTACTService();
this.dataSet = cs.Search(this.TextBoxString.Text.Trim().ToLower());

Please help.

Thank you.
 
J

Jan Tielens

You can throw Exceptions in a web service, which can be caught in your
client project. The only problem is that your exceptions need to pass a
boundary (=web service). You can check out following article which explains
how this can be done:
http://tinyurl.com/25j4q
Summary:

Sometimes things can go wrong when code is executed, so Exceptions are
thrown. When your application exposes services through a webservice layer,
SoapExceptions are thrown from the server to the client. By default normal
Exceptions are converted to a SoapException, resulting in a rather ugly
Exception containing all information concatenated in a long String. But
luckily the SOAP protocol allows any XML document to be included in SOAP
error messages. This article shows how to build some helper classes to
easily pass error information from the server to the client through a
webservice layer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top