简体   繁体   English

要在C#中使用RESTful Web服务,我应该使用HttpWebRequest吗?

[英]To consume a RESTful web service in C#, should I use HttpWebRequest?

How do I consume a RESTful web service in C# code? 如何在C#代码中使用RESTful Web服务?

NOTE: by RESTful, I mean non-SOAP. 注意:通过RESTful,我的意思是非SOAP。 For example, in the flickr API you can call their web service as follows to return JSON data: 例如,在flickr API中,您可以按如下方式调用其Web服务以返回JSON数据:

http://api.flickr.com/services/feeds/photos_public.gne?tags=cats&tagmode=any&format=json http://api.flickr.com/services/feeds/photos_public.gne?tags=cats&tagmode=any&format=json

Do I simply use HttpWebRequest? 我只是使用HttpWebRequest吗?

What if I'm using a web service that takes POST parameters? 如果我使用的是接受POST参数的Web服务怎么办? Would that use HttpWebRequest also? 那还会使用HttpWebRequest吗?

Is there any benefit to using WCF on the consumer side? 在消费者方面使用WCF有什么好处吗?

WCF provides a unified programming model for communication, so if you later decide that you do not want to use REST or you want to provide an extra type of endpoint for example SOAP, you only need tp change the configuration. WCF为通信提供了统一的编程模型,因此如果您以后决定不想使用REST,或者想要为SOAP提供额外类型的端点,则只需更改配置即可。

Take a look at REST for WCF: 看一下REST for WCF:

http://msdn.microsoft.com/en-us/netframework/cc950529.aspx http://msdn.microsoft.com/en-us/netframework/cc950529.aspx

Their is a demonstration and labs in the .NET Framework 3.5 Enhancements Training Kit, which provides two labs based around creating, servicing and consuming RESTFul services. 他们是.NET Framework 3.5增强培训工具包中的演示和实验,它提供了两个基于创建,服务和使用RESTFul服务的实验室。 The above link is the best MS combined resources of REST services. 以上链接是REST服务的最佳MS组合资源。

Bob. 鲍勃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM