WCF服务不可用-断电-什么错误 [英] WCF Service Not Available - Power Outage - What Error

查看:113
本文介绍了WCF服务不可用-断电-什么错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个非常简单的WCF服务,该服务由网页使用​​.我正在使用对象数据源来填充列表视图.后面的代码中没有代码.这一切都是由向导完成的.这个周末,由于洪水造成的停电,服务所在的服务器已关闭.由于服务已关闭,因此无法加载托管在异地的网页.今天,我正在尝试添加错误处理,该错误处理仍将让页面加载并且仅不填充列表视图.这比我想的要困难得多.我在哪里/应该如何捕捉例外?我所做的就是添加服务引用,然后使用向导访问对象数据源和列表视图.我仍然希望网页加载,并且不想转到自定义错误页面.这似乎应该很容易.我是否缺少明显的东西?这是一个ASP.NET 3.5网站.

谢谢,
Chuck

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

推荐答案

应在发起服务调用的客户端处理异常.这是讨论过的类似内容:
http://stackoverflow.com/questions/2816901/handling-service-unavailable- errors-in-asp-net [ ^ ]
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[^]


谢谢.在阅读和研究之后,我决定摆脱对象数据源,并以编程方式绑定listview.该服务返回一个列表,因此我正在检查列表计数以及它是否> 0我将数据源设置为列表,然后将其绑定.如果服务关闭,我将隐藏列表视图.如果服务关闭,错误将被捕获在代码的第一部分.我仍然感到惊讶的是,当服务关闭时整个页面都炸毁了,并且没有设置可以处理的设置,但这很容易.这是代码(这是背后代码中的唯一代码):

< pre lang ="vb">受保护的子lvCurrentTopics_Load(作为对象发送,作为System.EventArgs发送)处理lvCurrentTopics.Load
试试

''服务返回对象列表
作为新Generic.List(srbcweb_wcf.CurrentTopic)的变暗

''打开客户端并填充列表
使用c作为新的srbcweb_wcf.SRBCWeb_wcfClient

c.Open()

lst = c.GetCurrentTopics

c.Close()

最终使用

''检查列表是否已填充并设置listview的数据源
如果不是lst.Count = 0,则

lvCurrentTopics.DataSource = lst

lvCurrentTopics.DataBind()

其他

lvCurrentTopics.Visible = False

如果结束

异常捕获
lvCurrentTopics.Visible = False
''给我发错误
结束尝试

结束Sub</pre>
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>


这篇关于WCF服务不可用-断电-什么错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆