Newbie Q: Return Error to Page?

Discussion in 'ASP .Net Web Services' started by Soul, Feb 1, 2004.

  1. Soul

    Soul Guest

    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.

    --
    Soul
     
    Soul, Feb 1, 2004
    #1
    1. Advertising

  2. Soul

    Jan Tielens Guest

    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.

    --
    Greetz,
    Jan
    __________________________________
    Read my weblog: http://weblogs.asp.net/jan
    "Soul" <> schreef in bericht
    news:...
    > 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.
    >
    > --
    > Soul
    >
    >
    >
    >
     
    Jan Tielens, Feb 1, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. PvdK
    Replies:
    0
    Views:
    2,990
  2. =?Utf-8?B?UnVkeQ==?=

    Re: Newbie ? - Error on Redirect from login page error

    =?Utf-8?B?UnVkeQ==?=, Dec 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    371
    =?Utf-8?B?UnVkeQ==?=
    Dec 15, 2004
  3. wl
    Replies:
    2
    Views:
    593
    Dimitri Maziuk
    Mar 5, 2004
  4. Ganesh Gella
    Replies:
    4
    Views:
    366
    Stuart Gerchick
    Nov 12, 2004
  5. Greenhorn
    Replies:
    15
    Views:
    846
    Keith Thompson
    Mar 6, 2005
Loading...

Share This Page