OData 中的无效请求处理 [英] Invalid request handling in OData

查看:69
本文介绍了OData 中的无效请求处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C# 编写 OData 网络服务,我需要一些关于如何处理无效请求的建议?错误的一个例子是,如果客户请求对他们不再拥有的物品提供服务.理想情况下,我想确切地向客户报告无效的原因,因为有多种可能的原因.

Im writing an OData webservice with C# and I need some advice on how to handle invalid requests? An example of an error would be if a customer requested a service on an item they no longer own. I would idealy like to report back to the customer exactly why it is invalid as there are multiple possible reasons.

非常感谢

推荐答案

我建议使用 FaultContracts 作为 OperationContract 的一部分.您可以像 DataContracts 一样定义它们,也可以像自定义异常一样处理异常.

I would recommend using FaultContracts as part of the OperationContract. You can define them just like DataContracts, and handle exceptions just like a custom exception.

[OperationContract]
[FaultContract(typeof(ItemNotOwned))]
Item GetItem(int ItemId);

您可以将 ItemNotOwned 定义为单独的合同定义.

You would define ItemNotOwned as a seperate contract definition.

在 MSDN 上查看:http://msdn.microsoft.com/en-us/library/ms733841.aspx#Y323

Check it out on MSDN: http://msdn.microsoft.com/en-us/library/ms733841.aspx#Y323

这篇关于OData 中的无效请求处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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