easy upgrade WCF Service to RESTful


We are in kind of dilemma of choosing the architecture for our upcoming web applications. MVC or SL4? Because the first few pages we are going to build are quite simple, so I prefer to make it on REST+jQueryUI for now. It should be very easy to switch to either one in the future.

We already have the WCF service built, the only challenge is to make it RESTful.



Add webGet attribute/verb on Contract. Default response type is xml.

public interface ICountryProvinceWCFService

    string[] GetProvinceGET(string Country);


According to ms help WegGet is useless until web http behavior is defined in web.config.

Note: this is a endpoint behavior, not service behavior, this must be set on endpoint level.

Also, binding type needs to be webHttpBinding.

      <service behaviorConfiguration="DefaultServicesBehavior" name="MyWcfService">
        <endpoint address="" binding="wsHttpBinding" contract="IMyWcfService">
            <dns value="localhost" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="rest" binding="webHttpBinding" contract="IMyWcfService" behaviorConfiguration="RestfulWebServiceEndpointBehavior" />
            <add baseAddress="http://localhost/RestDemo" />

        <behavior name="RestfulWebServiceEndpointBehavior">
          <webHttp />





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s