Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I have a really simple WCF service that is consumed by a web page. I'm using an object datasource to populate a listview. I have no code in the code-behind. It was all done with the wizards. This weekend, due to a power outage caused by a flood, the server where the service resides was down. The webpage, hosted offsite, would not load because the service was down. Today, I'm trying to add error handling that will still let the page load and just not populate the listview. This has been more difficult that I thought it would be. Where/How should I catch the exception? All I did was add a service reference and then use wizards for the object datasource and listview. I still want the webpage to load and don't want to go over to a custom error page. This seems like it should be easy. Am I missing something obvious? It's an ASP.NET 3.5 website.

Thanks,
Chuck
Posted
Updated 12-Sep-11 8:51am
v2

The exception should be handled at the client side from where the service call is initiated. Here is something similar discussed:
http://stackoverflow.com/questions/2816901/handling-service-unavailable-errors-in-asp-net[^]
 
Share this answer
 
Thanks for the idea. After reading and researching, I decided to get rid of the object datasource and bind the listview programatically. The service returns a list so I'm checking the list count and if it's > 0 I'm setting the datasource to the list and then binding it. If the service is down, I hide the listview. If the service is down the error will be caught in the first section of the code. I'm still surprised the whole page blew up when the service was down and there isn't a setting to handle it, but this was easy enough. Here is the code (it's the only code in the code-behind):

<pre lang="vb"> Protected Sub lvCurrentTopics_Load(sender As Object, e As System.EventArgs) Handles lvCurrentTopics.Load
Try

' the service returns a list of objects
Dim lst As New Generic.List(Of srbcweb_wcf.CurrentTopic)

' open the client and populated the list
Using c As New srbcweb_wcf.SRBCWeb_wcfClient

c.Open()

lst = c.GetCurrentTopics

c.Close()

End Using

' check if the list is populated and set the datasource of the listview
If Not lst.Count = 0 Then

lvCurrentTopics.DataSource = lst

lvCurrentTopics.DataBind()

Else

lvCurrentTopics.Visible = False

End If

Catch ex As Exception
lvCurrentTopics.Visible = False
' send me the error
End Try

End Sub</pre>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900