[英]How can I get the type of thrown exception from CompletedEventArgs?
I use C# and Visual Studio 2012 to develop a WP8 application. 我使用C#和Visual Studio 2012来开发WP8应用程序。 I added a service reference to my project (Add Service Reference).
我为我的项目添加了一个服务引用(添加服务引用)。 So I am able to use webservice functions.
所以我可以使用webservice功能。
client = new YChatWebService.WebServiceControllerPortTypeClient();
client.getDataCompleted += client_getDataCompleted;
client.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 0, 0, 500);
client.getDataAsync();
void client_getDataCompleted(object sender, getDataCompletedEventArgs e)
{
// e.Error.Message
}
I have set up a timeout limit 500ms for getData()
; 我为
getData()
设置了500ms的超时限制; If the time limit is exceeded then I get following error: 如果超过时间限制,则会出现以下错误:
"The HTTP request to 'http://example.com/webService/index?ws=1' has exceeded the allotted timeout. The time allotted to this operation may have been a portion of a longer timeout."
“对'http://example.com/webService/index?ws=1'的HTTP请求已超出分配的超时时间。分配给此操作的时间可能是较长超时的一部分。”
That is nice :) However, I would like to find out what kind of exception was thrown. 这很好:)但是,我想知道抛出了什么样的异常。 Something like a string variable containing a string "
TimeoutException
" would be nice. 像包含字符串“
TimeoutException
”的字符串变量之类的东西会很好。 How can I achive that? 我怎么能做到这一点?
You could use 你可以用
if( e.Error is TimeoutException )
To see if the Exception is of the type TimeoutException 查看Exception是否为TimeoutException类型
Isn't this more that the http response from the server contains the error description, not a .net exception? 这不是来自服务器的http响应包含错误描述,而不是.net异常吗?
Does the e.Error class have any other properties other than 'Message'? e.Error类是否具有“Message”以外的任何其他属性? If the server is also .net, then you might be able to match the exception type, but if it's not .net they won't correspond.
如果服务器也是.net,那么您可能能够匹配异常类型,但如果它不是.net则它们将不对应。
If there is an error code returned, I would just use this, or just search for the text 'exceeded the allotted timeout', to confirm that it was a timeout exception. 如果返回了错误代码,我只会使用它,或只搜索“超出分配的超时”文本,以确认它是超时异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.