Web service error in InfoPath

B

BowieM

Hi,

I am submitting an Infopath form to SQL server via a web service that calls
a stored procedure.

At some point I renamed the stored procedure without correcting the change
in the web service.

However, when I submitted the form using the web service, InfoPath returned
"successful" submit message! Of course no form was inserted to the SQL Server.

I then proceeded to test the web service outside of InfoPath and I got an
error message informing me that the stored procedure does not exist.

How can I pass on this message from the web service to InfoPath or failing
that how I can InfoPath pick up web service errors such as this?
 
S

S.Y.M. Wong-A-Ton

Is your web service throwing errors? Or consuming them? InfoPath will display
an error box if the web service throws an error.
 
B

BowieM

Hi S.Y.M.

It is the web service that is throwing an error but InfoPath is "pick it
up". Instead InfoPath displays "The form was submitted successfully" when in
fact it wasn't.

How do I pass the error being thrown by the web service to an error box in
InfoPath?
 
S

S.Y.M. Wong-A-Ton

Hi Bowie,

I understand what you're trying to do and how your form is behaving. What
I'm trying to say is that perhaps you are catching the error in your web
service and not re-throwing it? If you catch an error and do not re-throw it,
InfoPath will not show you the error box. I've tested both submit and
retrieve data connections to web services and InfoPath behaves correctly,
i.e., I'm shown an error when I expect one.

How are you calling the web service? Through rules or code?
 
S

S.Y.M. Wong-A-Ton

I just realized that my previous post might not have been clear enough... For
InfoPath to show an error box, the last result returned from the web method
you are calling from your form must be an error. So if your web service
returns false or true, or 0 or 1 to indicate failure or success, InfoPath
will not display an error. The response that comes back from your web service
must be an error, so you must either not catch errors in your web method or
re-throw them in the catch block if you are catching them.
 
B

BowieM

Hi S.Y.M.

Thanks for showing a great interest in my predicament. I really appreciate
your effort. And maybe I need to do some more work rather than look for a
silver bullet?

I had a try.. catch that caught a SqlException. Here is a snippet of my web
service in C#:

--
[System.Web.Services.WebMethod()]
public string insertSummaryReport(string xmlReport)
{
try
{
//Code to call a SQL Server stored procedure here
} catch (SqlException e)
{
return "Error " + e.ErrorCode + " " + e.Message.ToString();
}
}
---

When I run the web service in Visual Studio (ctrl + F5) I get the following
error displayed in the browser (Note that I have since corrected my original
reported error):

<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://po.ijs.gov.za/">515 : Cannot insert the value NULL
into column 'ProjectNo', table 'ijspo.dbo.SummaryReport'; column does not
allow nulls. INSERT fails.</string>
---

Based on your submission I changed the web service not to return a string
but to throw the exception.

However, InfoPath is still submitting the form successfully and I can longer
see the error when I run the web service with ctrl + F5 in Visual Studio!

Am I trying to have my cake and eat it at the same time? Do I need to build
SOAP extensions? My background is Java and you can see I'm VERY new to both
ASP.NET, C#, InfoPath and Web Services. For example I could have expected to
thro the exception as follows:

public string insertSummaryReport(string xmlReport) throw SqlException

but C# demands that I do that with the catch as follows

try
{
} catch (SqlException e)
{
throw e;
}

What am I doing wrong or missing? Like I said maybe I'm looking for a silver
bulet here which does not exist! Thanks for the help.
 
S

S.Y.M. Wong-A-Ton

I see my last post was more confusing than helpful. Sorry about that, Bowie.

You are almost there! It is fine for your web method to return a string, but
as I suspected, you are handling the error in your web method and not
throwing it for InfoPath to catch it. So here is what you can try:

[System.Web.Services.WebMethod()]
public string insertSummaryReport(string xmlReport)
{
try
{
//Code to call a SQL Server stored procedure here

//Everything went OK, so return the result as a string
return retVal; //where retVal is whatever you want to return as a
string
}
catch (SqlException e)
{
//This will raise the error box in InfoPath
throw new ApplicationException("Error " + e.ErrorCode + " " +
e.Message.ToString());
}
catch (Exception ex)
{
throw(ex); //this will catch anything not previously caught and
raise the error box in InfoPath
}
finally
{
//Cleanup code goes here
}
}

Hope this helps.
---
S.Y.M. Wong-A-Ton


BowieM said:
Hi S.Y.M.

Thanks for showing a great interest in my predicament. I really appreciate
your effort. And maybe I need to do some more work rather than look for a
silver bullet?

I had a try.. catch that caught a SqlException. Here is a snippet of my web
service in C#:

--
[System.Web.Services.WebMethod()]
public string insertSummaryReport(string xmlReport)
{
try
{
//Code to call a SQL Server stored procedure here
} catch (SqlException e)
{
return "Error " + e.ErrorCode + " " + e.Message.ToString();
}
}
---

When I run the web service in Visual Studio (ctrl + F5) I get the following
error displayed in the browser (Note that I have since corrected my original
reported error):

<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://po.ijs.gov.za/">515 : Cannot insert the value NULL
into column 'ProjectNo', table 'ijspo.dbo.SummaryReport'; column does not
allow nulls. INSERT fails.</string>
---

Based on your submission I changed the web service not to return a string
but to throw the exception.

However, InfoPath is still submitting the form successfully and I can longer
see the error when I run the web service with ctrl + F5 in Visual Studio!

Am I trying to have my cake and eat it at the same time? Do I need to build
SOAP extensions? My background is Java and you can see I'm VERY new to both
ASP.NET, C#, InfoPath and Web Services. For example I could have expected to
thro the exception as follows:

public string insertSummaryReport(string xmlReport) throw SqlException

but C# demands that I do that with the catch as follows

try
{
} catch (SqlException e)
{
throw e;
}

What am I doing wrong or missing? Like I said maybe I'm looking for a silver
bulet here which does not exist! Thanks for the help.
--
Regards,
Bowie M


S.Y.M. Wong-A-Ton said:
I just realized that my previous post might not have been clear enough... For
InfoPath to show an error box, the last result returned from the web method
you are calling from your form must be an error. So if your web service
returns false or true, or 0 or 1 to indicate failure or success, InfoPath
will not display an error. The response that comes back from your web service
must be an error, so you must either not catch errors in your web method or
re-throw them in the catch block if you are catching them.
 
B

BowieM

Hi S.Y.M,

Thanks a millison. It worked. The error was finally displayed in InfoPath
error box.

I guess the "trick" is to throw an ApplicationException().

--
On a final note (and this not really bothering me at the moment and I am
adding it as an addendum to this), when testing the web service using
ctrl+F5, the browser is unable to show the error message. After clicking the
refresh button the browser displays the following error "Request format is
unrecognised for URL unexpectedly ending in '/insertSummaryReport'. NB:
"insertSummaryReport" is the name of the web service. I know I may have to
"ToString" the exception being thrown for the browser to display but I'll
leave that for another day. Thanks a million once more.
--
Regards,
Bowie M


S.Y.M. Wong-A-Ton said:
I see my last post was more confusing than helpful. Sorry about that, Bowie.

You are almost there! It is fine for your web method to return a string, but
as I suspected, you are handling the error in your web method and not
throwing it for InfoPath to catch it. So here is what you can try:

[System.Web.Services.WebMethod()]
public string insertSummaryReport(string xmlReport)
{
try
{
//Code to call a SQL Server stored procedure here

//Everything went OK, so return the result as a string
return retVal; //where retVal is whatever you want to return as a
string
}
catch (SqlException e)
{
//This will raise the error box in InfoPath
throw new ApplicationException("Error " + e.ErrorCode + " " +
e.Message.ToString());
}
catch (Exception ex)
{
throw(ex); //this will catch anything not previously caught and
raise the error box in InfoPath
}
finally
{
//Cleanup code goes here
}
}

Hope this helps.
---
S.Y.M. Wong-A-Ton


BowieM said:
Hi S.Y.M.

Thanks for showing a great interest in my predicament. I really appreciate
your effort. And maybe I need to do some more work rather than look for a
silver bullet?

I had a try.. catch that caught a SqlException. Here is a snippet of my web
service in C#:

--
[System.Web.Services.WebMethod()]
public string insertSummaryReport(string xmlReport)
{
try
{
//Code to call a SQL Server stored procedure here
} catch (SqlException e)
{
return "Error " + e.ErrorCode + " " + e.Message.ToString();
}
}
---

When I run the web service in Visual Studio (ctrl + F5) I get the following
error displayed in the browser (Note that I have since corrected my original
reported error):

<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://po.ijs.gov.za/">515 : Cannot insert the value NULL
into column 'ProjectNo', table 'ijspo.dbo.SummaryReport'; column does not
allow nulls. INSERT fails.</string>
---

Based on your submission I changed the web service not to return a string
but to throw the exception.

However, InfoPath is still submitting the form successfully and I can longer
see the error when I run the web service with ctrl + F5 in Visual Studio!

Am I trying to have my cake and eat it at the same time? Do I need to build
SOAP extensions? My background is Java and you can see I'm VERY new to both
ASP.NET, C#, InfoPath and Web Services. For example I could have expected to
thro the exception as follows:

public string insertSummaryReport(string xmlReport) throw SqlException

but C# demands that I do that with the catch as follows

try
{
} catch (SqlException e)
{
throw e;
}

What am I doing wrong or missing? Like I said maybe I'm looking for a silver
bulet here which does not exist! Thanks for the help.
--
Regards,
Bowie M


S.Y.M. Wong-A-Ton said:
I just realized that my previous post might not have been clear enough... For
InfoPath to show an error box, the last result returned from the web method
you are calling from your form must be an error. So if your web service
returns false or true, or 0 or 1 to indicate failure or success, InfoPath
will not display an error. The response that comes back from your web service
must be an error, so you must either not catch errors in your web method or
re-throw them in the catch block if you are catching them.
---
S.Y.M. Wong-A-Ton


:

Hi S.Y.M.

It is the web service that is throwing an error but InfoPath is "pick it
up". Instead InfoPath displays "The form was submitted successfully" when in
fact it wasn't.

How do I pass the error being thrown by the web service to an error box in
InfoPath?
--
Thanks & Regards,
Bowie M


:

Is your web service throwing errors? Or consuming them? InfoPath will display
an error box if the web service throws an error.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am submitting an Infopath form to SQL server via a web service that calls
a stored procedure.

At some point I renamed the stored procedure without correcting the change
in the web service.

However, when I submitted the form using the web service, InfoPath returned
"successful" submit message! Of course no form was inserted to the SQL Server.

I then proceeded to test the web service outside of InfoPath and I got an
error message informing me that the stored procedure does not exist.

How can I pass on this message from the web service to InfoPath or failing
that how I can InfoPath pick up web service errors such as this?
 
S

S.Y.M. Wong-A-Ton

Glad it worked! The trick is not to throw an ApplicationException, but just
to throw an Exception. I used ApplicationException, because you wanted to
create a customized error message to return to the user.

Unfortunately I do not yet have a solution to your "note". There might be a
more elegant way to raise errors in InfoPath, but I haven't found it yet.
---
S.Y.M. Wong-A-Ton


BowieM said:
Hi S.Y.M,

Thanks a millison. It worked. The error was finally displayed in InfoPath
error box.

I guess the "trick" is to throw an ApplicationException().

--
On a final note (and this not really bothering me at the moment and I am
adding it as an addendum to this), when testing the web service using
ctrl+F5, the browser is unable to show the error message. After clicking the
refresh button the browser displays the following error "Request format is
unrecognised for URL unexpectedly ending in '/insertSummaryReport'. NB:
"insertSummaryReport" is the name of the web service. I know I may have to
"ToString" the exception being thrown for the browser to display but I'll
leave that for another day. Thanks a million once more.
--
Regards,
Bowie M


S.Y.M. Wong-A-Ton said:
I see my last post was more confusing than helpful. Sorry about that, Bowie.

You are almost there! It is fine for your web method to return a string, but
as I suspected, you are handling the error in your web method and not
throwing it for InfoPath to catch it. So here is what you can try:

[System.Web.Services.WebMethod()]
public string insertSummaryReport(string xmlReport)
{
try
{
//Code to call a SQL Server stored procedure here

//Everything went OK, so return the result as a string
return retVal; //where retVal is whatever you want to return as a
string
}
catch (SqlException e)
{
//This will raise the error box in InfoPath
throw new ApplicationException("Error " + e.ErrorCode + " " +
e.Message.ToString());
}
catch (Exception ex)
{
throw(ex); //this will catch anything not previously caught and
raise the error box in InfoPath
}
finally
{
//Cleanup code goes here
}
}

Hope this helps.
---
S.Y.M. Wong-A-Ton


BowieM said:
Hi S.Y.M.

Thanks for showing a great interest in my predicament. I really appreciate
your effort. And maybe I need to do some more work rather than look for a
silver bullet?

I had a try.. catch that caught a SqlException. Here is a snippet of my web
service in C#:

--
[System.Web.Services.WebMethod()]
public string insertSummaryReport(string xmlReport)
{
try
{
//Code to call a SQL Server stored procedure here
} catch (SqlException e)
{
return "Error " + e.ErrorCode + " " + e.Message.ToString();
}
}
---

When I run the web service in Visual Studio (ctrl + F5) I get the following
error displayed in the browser (Note that I have since corrected my original
reported error):

<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://po.ijs.gov.za/">515 : Cannot insert the value NULL
into column 'ProjectNo', table 'ijspo.dbo.SummaryReport'; column does not
allow nulls. INSERT fails.</string>
---

Based on your submission I changed the web service not to return a string
but to throw the exception.

However, InfoPath is still submitting the form successfully and I can longer
see the error when I run the web service with ctrl + F5 in Visual Studio!

Am I trying to have my cake and eat it at the same time? Do I need to build
SOAP extensions? My background is Java and you can see I'm VERY new to both
ASP.NET, C#, InfoPath and Web Services. For example I could have expected to
thro the exception as follows:

public string insertSummaryReport(string xmlReport) throw SqlException

but C# demands that I do that with the catch as follows

try
{
} catch (SqlException e)
{
throw e;
}

What am I doing wrong or missing? Like I said maybe I'm looking for a silver
bulet here which does not exist! Thanks for the help.
--
Regards,
Bowie M


:

I just realized that my previous post might not have been clear enough... For
InfoPath to show an error box, the last result returned from the web method
you are calling from your form must be an error. So if your web service
returns false or true, or 0 or 1 to indicate failure or success, InfoPath
will not display an error. The response that comes back from your web service
must be an error, so you must either not catch errors in your web method or
re-throw them in the catch block if you are catching them.
---
S.Y.M. Wong-A-Ton


:

Hi S.Y.M.

It is the web service that is throwing an error but InfoPath is "pick it
up". Instead InfoPath displays "The form was submitted successfully" when in
fact it wasn't.

How do I pass the error being thrown by the web service to an error box in
InfoPath?
--
Thanks & Regards,
Bowie M


:

Is your web service throwing errors? Or consuming them? InfoPath will display
an error box if the web service throws an error.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am submitting an Infopath form to SQL server via a web service that calls
a stored procedure.

At some point I renamed the stored procedure without correcting the change
in the web service.

However, when I submitted the form using the web service, InfoPath returned
"successful" submit message! Of course no form was inserted to the SQL Server.

I then proceeded to test the web service outside of InfoPath and I got an
error message informing me that the stored procedure does not exist.

How can I pass on this message from the web service to InfoPath or failing
that how I can InfoPath pick up web service errors such as this?
 

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

Top