BT

Dynamic C# in Action

| by Jonathan Allen Follow 577 Followers on Nov 10, 2008. Estimated reading time: 1 minute |

REST-style web service calls have a significant advantage over SOAP based ones in that they do not require tooling support. This makes them particularly easy to call from languages such as Ruby or Python. Unfortunately, the same cannot be said for C#, where the lack of tooling works against the developer.

The reason for this difference is dynamic typing. Languages like Ruby and Python can turn JSON and XML-based results directly into an object model. This can then be accessed using each languages standard method and property syntax. For languages like C#, no such mapping is possible without knowing ahead of time what they object graph is going to look like. This involves a tedious and error-prone process of hand-coding the necessary classes and parsing logic.

With C# 4, all this goes away. By combining it with Nikhil Kothari's Dynamic Rest project, C# and VB developers can get the same clean syntax that the dynamic programmers have come to expect. Since it is based on the early preview, there are some limitations,

Note that in the CTP, there isn't any support for indexers used against dynamic types, which gets in the way of normal array syntax. Hence the workaround above using Item(). However, I've been told, that support for indexing into dynamic types already exists in later builds.

In a follow-up post Nikhil demonstrates using C# 4 to call Amazon and Flickr services.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Myth - SOAP needs tooling by Paul Fremantle

It is a complete myth that SOAP requires tooling while REST doesn't. They both require you to read and write some data representation - whether its XML or JSon doesn't really matter. If you have an XML parser or toolkit you can create a SOAP message just as easily as you can do REST. Tooling helps, but tooling can help with REST too.

Paul Fremantle, CTO, WSO2

Re: Myth - SOAP needs tooling by Jonathan Allen

Honestly though, how often do you people actually trying to hand-roll SOAP messages? Sure it can be done, but the complexity level is so high it just doesn't make sense to do so.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT