Silverlight 中的服务器端异常处理

编程入门 行业动态 更新时间:2024-10-25 10:29:58
本文介绍了Silverlight 中的服务器端异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为我的 Silverlight 应用程序使用 WCF REST 服务.当我抛出错误代码为 500 的 webfault 异常时.银灯显示错误消息:'Error:404 File not found'.我做了一些研究,发现这是浏览器的问题,即浏览器堆栈只能将两个响应代码 200 和 404 传递给这里的任何插件,在我的情况下是 Silverlight.这意味着当服务器端出现 webfault 异常时,SL 只会显示消息找不到文件".我希望将错误消息传递给客户端.一种这样的解决方案是传递响应代码 200 并将错误消息发送到附加到一些类似逻辑的返回对象的客户端.我想知道是否还有其他可能,这样我就不必更改我的班级结构.我也从服务器返回 JSON 对象.我基本上需要用 SilverLight 来获取 200 和 400 系列以外的响应代码.

I am using WCF REST Service for my silverlight application. When I throw a webfault exception with error code 500. The silver light displays the error message:'Error:404 File not found'. I did some research and found that it is the problem with browser i.e. the browser stack can only pass two response codes, 200 and 404 to any plugin here in my case its silverlight. That means when ever there is a webfault exception at the server side the SL will only display the message 'File not found'. I want the error message to be passed to the client. One such solution is to pass the response code 200 and send the error message to the client attached to the return object of some similar logic like this. I want know if there is anything else that is possible so that I dont have to change my class structure. Also I am returning JSON objects from the server. I basically need to SilverLight to get response codes other than 200 and 400 series.

推荐答案

Microsoft 添加了 在他们发布 Silverlight 3 时为您提供单独的 HTTP 堆栈.

Microsoft added a separate HTTP stack for your purpose when they released Silverlight 3.

指定 HTTP 堆栈很容易.您只需调用WebRequest.RegisterPrefix 方法,将 ClientHttp 对象传递给指定要指定的客户端 HTTP 处理或 BrowserHttp 对象浏览器 HTTP 处理.您在发出任何网络请求之前执行此操作.

Specifying the HTTP stack is easy. You simply call the WebRequest.RegisterPrefix method, passing the ClientHttp object to specify client HTTP handling or a BrowserHttp object to specify browser HTTP handling. You do this before you make any web requests.

新堆栈比旧堆栈的限制更少,因为它可以处理更多的 HTTP 方法,并且可以处理任何 HTTP 返回码.有关更广泛的比较,请参阅链接博客文章中的图表.

The new stack has less limitations than the old one in that it can handle more HTTP methods and it can handle any HTTP return code. See the chart in the linked blog post for a more extensive comparison.

更多推荐

Silverlight 中的服务器端异常处理

本文发布于:2023-11-13 01:41:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器端   异常   Silverlight

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!