开发者

WCF or HttpWebRequest - Which to Use?

开发者 https://www.devze.com 2022-12-15 07:49 出处:网络
I would like to access to multiple web services with a WPF application (Facebook, Twitter, etc...). I\'m not familiar at all with WCF and I was wondering what should I use and 开发者_如何学编程why (

I would like to access to multiple web services with a WPF application (Facebook, Twitter, etc...).

I'm not familiar at all with WCF and I was wondering what should I use and 开发者_如何学编程why (pros and cons) ? WCF or something else more traditional (like HttpWebRequest) ?


Go with 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.

Get yourself a good book - I recommend Learning WCF by Michele Leroux Bustamante - check out her samples, play with those.

Also check out online resources:

  • WCF Developer Center on MSDN with tons of articles, screen casts etc.
  • Dotnet Rocks TV: Keith Elder Demystifies WCF
  • Dotnet Rocks TV: Miguel Castro's Extreme WCF

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. 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.

More online resources for WCF REST and Twitter:

  • MSDN Developer Center for WCF REST
  • Pluralsight Screencast library on WCF REST
  • Screencast: Using HttpClient to consume Twitter in under 3 minutes


Why be "traditional" when you can get WCF to do some of the work for you?

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?


I've developed with both WCF and straight web requests.

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).

Also WCF has the advantage of being hosted anywhere you want, like Console, Web site, WPF application, or Windows Service. When it comes to configuration there is a high learning curve with WCF, so understand that going in.

More and more third party services are adopting a REST interface. This means most of your calls out will be done using the 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). If it is XML or JSon, look into using the XmlSerializer or DataContractSerializer.

So if you are writing your own web service (calls coming in), go ahead and use WCF. If you are consuming a web service (calling out to a service i.e. Twitter) you most likely won't have the choice to use WCF.

0

精彩评论

暂无评论...
验证码 换一张
取 消