如何使用/创建 wcf 休息方法 [英] How to use / create wcf rest methods

查看:25
本文介绍了如何使用/创建 wcf 休息方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然制作我的第一个 WCF REST 服务,我有一个简单的问题.我希望我的服务能在 php、python、java 和 asp.net 中使用

i still make my FIRST WCF REST service and i have a simple question. I hope so my service will be use from php, python, java and asp.net

怎么做更好:

  • 设置/返回对象作为方法参数,或者更好的是在数组中工作?
  • 所有参数都采用字符串或正常类型(int、string、float等)

我认为对于 ASP.NET 更好的是使用对象,但在 jquery/php 数组中?

I think for ASP.NET better is use objects, but in jquery / php arrays ?

如果我使用数组(可能是字符串),我会有很多转换,我必须记住什么索引返回值,在对象模型中我会有很多 DTO 对象.

If i use arrays (probably string) i will have a lot of conversion and i must remember what index return how value, in object model i will have a lot of DTO objects.

如何做到最优.也许构建具有大量字符串变量的方法,对其进行验证,打包到 poco 类(有时/经常)该类中的某些参数将为空,将其发送到存储库类并将其添加到数据库中.以返回方式从数据库中获取您想要的内容(带有 null 的 poco 类,因为您并不总是选择所有字段),并将结果返回到数组.

How to do it optymality. Maybe build methods with a lot of string variables, validate it, packed to poco class (sometimes / often) some parameters in this class will be null, send it to repository class and add it to database. In return way take what you want from database (poco class with null, becouse you not always take select all fields), and returns result to array.

推荐答案

我建议您使用一些标准,例如 Atom 来打包您的输出(并接受非 GET 输入).大多数语言都有 Atom 读取器/写入器,因此几乎任何语言的开发人员都可以更轻松地与您的 REST 服务进行互操作.在 WCF 方面,您可以使用 .NET Atom/RSS 库,因此对您来说也更容易.这也将允许您通过 POST/PUT 将输入作为 Atom 提要.

I suggest you use some standard such as Atom for packaging your outputs (and accepting non-GET inputs). Most languages have Atom readers/writers so developers in pretty much any language will have an easier time inter-operating with your REST service. On the WCF side you can use the .NET Atom/RSS libraries, so it is easier for you too. This would also allow you to take inputs as Atom feeds through POST/PUT.

这不是什么新鲜事,而且有很多先例 这样做.我做过,觉得有一些优点.

This not something new, and there is plenty of precedent on doing this. I've done it and feel it has some advantages.

这篇关于如何使用/创建 wcf 休息方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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