简体   繁体   English

WCF或HttpWebRequest-使用哪个?

[英]WCF or HttpWebRequest - Which to Use?

I would like to access to multiple web services with a WPF application (Facebook, Twitter, etc...). 我想使用WPF应用程序(Facebook,Twitter等...)访问多个Web服务。

I'm not familiar at all with WCF and I was wondering what should I use and why (pros and cons) ? 我对WCF一点都不熟悉,我想知道应该使用什么,为什么使用(优点和缺点)? WCF or something else more traditional (like HttpWebRequest) ? WCF还是其他更传​​统的东西(例如HttpWebRequest)?

Why be "traditional" when you can get WCF to do some of the work for you? 当您可以让WCF为您完成某些工作时,为什么要“传统”?

If you're accessing a number of services, you'll be writing a lot of duplicate code. 如果要访问许多服务,则会编写很多重复的代码。 You might then refactor the duplication into a framework for calling the services. 然后,您可以将重复项重构为用于调用服务的框架。

WCF already is such a framework, so why write your own? WCF已经这样一个框架,那么为什么要编写自己的框架?

Go with WCF! 使用WCF! It's the way to go, it's the present and future of Microsoft's "connected systems" strategy. 这是要走的路,这是微软“连接系统”战略的现在和将来。 You can attach to just about anything using WCF - and contrary to Khalid, I don't think it has a really high learning curve. 使用WCF,您几乎可以附加任何内容-与Khalid相反,我认为它的学习曲线并不高。

Get yourself a good book - I recommend Learning WCF by Michele Leroux Bustamante - check out her samples, play with those. 为自己准备一本好书-我建议Michele Leroux Bustamante撰写的Learning WCF-查看她的样本,并与他们一起玩。

Also check out online resources: 另请查看在线资源:

That should easily get you started! 那应该很容易让您入门! There's a ton more stuff out there. 还有更多的东西。

Watch those two DNR-TV screen casts - they show how to really understand what is needed in terms of WCF configuration. 看这两个DNR-电视屏幕投射-他们展示如何真正了解什么是必要的WCF配置方面。 It's really not rocket science! 这真的不是火箭科学! But unfortunately, the "Add Service Reference" and svcutil.exe both have a tendency to create awfully and overly complicated configs - that's not necessary. 但是不幸的是,“添加服务参考”和svcutil.exe都倾向于创建非常复杂的配置,这是不必要的。

More online resources for WCF REST and Twitter: 有关WCF REST和Twitter的更多在线资源:

I've developed with both WCF and straight web requests. 我已经使用WCF和直接Web请求进行了开发。

WCF can be great when developing web services, but there is no guarantee that all third party services will be implementing a protocol that works with WCF (add service reference or svcutil). 在开发Web服务时,WCF可能很棒,但不能保证所有第三方服务都将实现与WCF一起使用的协议(添加服务引用或svcutil)。

Also WCF has the advantage of being hosted anywhere you want, like Console, Web site, WPF application, or Windows Service. 此外,WCF的优点是可以将其托管在所需的任何位置,例如控制台,网站,WPF应用程序或Windows服务。 When it comes to configuration there is a high learning curve with WCF, so understand that going in. 在配置方面,WCF的学习曲线很高,因此请理解。

More and more third party services are adopting a REST interface. 越来越多的第三方服务正在采用REST接口。 This means most of your calls out will be done using the HttpWebRequest. 这意味着您的大部分呼叫将使用HttpWebRequest完成。 Once you make the call to the service, you will have the issue of deserializing the data coming back (XML, JSON, Key/Value Pair, Fixed Length). 调用该服务后,将出现反序列化返回的数据(XML,JSON,键/值对,固定长度)的问题。 If it is XML or JSon, look into using the XmlSerializer or DataContractSerializer. 如果是XML或JSon,请考虑使用XmlSerializer或DataContractSerializer。

So if you are writing your own web service (calls coming in), go ahead and use WCF. 因此,如果您要编写自己的Web服务(有来电),请继续使用WCF。 If you are consuming a web service (calling out to a service ie Twitter) you most likely won't have the choice to use WCF. 如果您正在使用Web服务(调出服务即Twitter),则很可能无法选择使用WCF。

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

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