Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Tuesday, January 13, 2015

Time Zone clonflictions with Cloud Services .. How to avoid .

There is problems when you are developing applications which based on cloud services. That is , time of your service (servers ) are different than the time that your application. If you are using time stamp based data pulling  from the cloud service you are in big trouble.

Here if two basic solutions that you can use in those scenarios
1. Use UTC (absolute) Time (highly recommended)
2. Change time zone of the server according to the  requirement

Use absolute time you can just do with simple DateTime object.
in C# simply like this
DateTime.UtcNow

Change Time zone of the Server ( Instances of cloud service )
This is the Task that you cannot find lot of documentation
 If you follow following steps You can easily change server time zone ( In azure (cloud) it will randomly create and no one can predict that which instance of the server will run entire service life cycle *Its never happens with cloud) in every running instance once it starting


1. Create batch (*.bat) file with flowing command
tzutil /s "Sri Lanka Standard Time" 
 

Here is time zone reference 

IndexName of Time ZoneTime
000Dateline Standard Time(GMT-12:00) International Date Line West
001Samoa Standard Time(GMT-11:00) Midway Island, Samoa
002Hawaiian Standard Time(GMT-10:00) Hawaii
003Alaskan Standard Time(GMT-09:00) Alaska
004Pacific Standard Time(GMT-08:00) Pacific Time (US and Canada); Tijuana
010Mountain Standard Time(GMT-07:00) Mountain Time (US and Canada)
013Mexico Standard Time 2(GMT-07:00) Chihuahua, La Paz, Mazatlan
015U.S. Mountain Standard Time(GMT-07:00) Arizona
020Central Standard Time(GMT-06:00) Central Time (US and Canada
025Canada Central Standard Time(GMT-06:00) Saskatchewan
030Mexico Standard Time(GMT-06:00) Guadalajara, Mexico City, Monterrey
033Central America Standard Time(GMT-06:00) Central America
035Eastern Standard Time(GMT-05:00) Eastern Time (US and Canada)
040U.S. Eastern Standard Time(GMT-05:00) Indiana (East)
045S.A. Pacific Standard Time(GMT-05:00) Bogota, Lima, Quito
050Atlantic Standard Time(GMT-04:00) Atlantic Time (Canada)
055S.A. Western Standard Time(GMT-04:00) Caracas, La Paz
056Pacific S.A. Standard Time(GMT-04:00) Santiago
060Newfoundland and Labrador Standard Time(GMT-03:30) Newfoundland and Labrador
065E. South America Standard Time(GMT-03:00) Brasilia
070S.A. Eastern Standard Time(GMT-03:00) Buenos Aires, Georgetown
073Greenland Standard Time(GMT-03:00) Greenland
075Mid-Atlantic Standard Time(GMT-02:00) Mid-Atlantic
080Azores Standard Time(GMT-01:00) Azores
083Cape Verde Standard Time(GMT-01:00) Cape Verde Islands
085GMT Standard Time(GMT) Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London
090Greenwich Standard Time(GMT) Casablanca, Monrovia
095Central Europe Standard Time(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
100Central European Standard Time(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb
105Romance Standard Time(GMT+01:00) Brussels, Copenhagen, Madrid, Paris
110W. Europe Standard Time(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
113W. Central Africa Standard Time(GMT+01:00) West Central Africa
115E. Europe Standard Time(GMT+02:00) Bucharest
120Egypt Standard Time(GMT+02:00) Cairo
125FLE Standard Time(GMT+02:00) Helsinki, Kiev, Riga, Sofia, Tallinn, Vilnius
130GTB Standard Time(GMT+02:00) Athens, Istanbul, Minsk
135Israel Standard Time(GMT+02:00) Jerusalem
140South Africa Standard Time(GMT+02:00) Harare, Pretoria
145Russian Standard Time(GMT+03:00) Moscow, St. Petersburg, Volgograd
150Arab Standard Time(GMT+03:00) Kuwait, Riyadh
155E. Africa Standard Time(GMT+03:00) Nairobi
158Arabic Standard Time(GMT+03:00) Baghdad
160Iran Standard Time(GMT+03:30) Tehran
165Arabian Standard Time(GMT+04:00) Abu Dhabi, Muscat
170Caucasus Standard Time(GMT+04:00) Baku, Tbilisi, Yerevan
175Transitional Islamic State of Afghanistan Standard Time(GMT+04:30) Kabul
180Ekaterinburg Standard Time(GMT+05:00) Ekaterinburg
185West Asia Standard Time(GMT+05:00) Islamabad, Karachi, Tashkent
190India Standard Time(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi
193Nepal Standard Time(GMT+05:45) Kathmandu
195Central Asia Standard Time(GMT+06:00) Astana, Dhaka
200Sri Lanka Standard Time(GMT+06:00) Sri Jayawardenepura
201N. Central Asia Standard Time(GMT+06:00) Almaty, Novosibirsk
203Myanmar Standard Time(GMT+06:30) Yangon Rangoon
205S.E. Asia Standard Time(GMT+07:00) Bangkok, Hanoi, Jakarta
207North Asia Standard Time(GMT+07:00) Krasnoyarsk
210China Standard Time(GMT+08:00) Beijing, Chongqing, Hong Kong SAR, Urumqi
215Singapore Standard Time(GMT+08:00) Kuala Lumpur, Singapore
220Taipei Standard Time(GMT+08:00) Taipei
225W. Australia Standard Time(GMT+08:00) Perth
227North Asia East Standard Time(GMT+08:00) Irkutsk, Ulaanbaatar
230Korea Standard Time(GMT+09:00) Seoul
235Tokyo Standard Time(GMT+09:00) Osaka, Sapporo, Tokyo
240Yakutsk Standard Time(GMT+09:00) Yakutsk
245A.U.S. Central Standard Time(GMT+09:30) Darwin
250Cen. Australia Standard Time(GMT+09:30) Adelaide
255A.U.S. Eastern Standard Time(GMT+10:00) Canberra, Melbourne, Sydney
260E. Australia Standard Time(GMT+10:00) Brisbane
265Tasmania Standard Time(GMT+10:00) Hobart
270Vladivostok Standard Time(GMT+10:00) Vladivostok
275West Pacific Standard Time(GMT+10:00) Guam, Port Moresby
280Central Pacific Standard Time(GMT+11:00) Magadan, Solomon Islands, New Caledonia
285Fiji Islands Standard Time(GMT+12:00) Fiji Islands, Kamchatka, Marshall Islands
290New Zealand Standard Time(GMT+12:00) Auckland, Wellington
300Tonga Standard Time(GMT+13:00) Nuku'alofa

2. Add it in to the cloud service ( Not to the cloud service project )

*Add it to project which identifies as role (web, worker) by cloud project . In following example You need to add batch file into WebRole1 project


















3. Then R-Click on the batch file and select properties from visual studio . In properties under the Advanced change Copy To Output Directory property in to copy always.











4. Then go to the Cloud project and open the ServiceDefinition.csdf file






5. Under WebRole Tag add Start up task as follow .

 <WebRole name="*****" vmsize="Small">
    <Startup>
      <Task commandLine="NameOfBatchFile.bat" executionContext="elevated" taskType="simple"/>
    </Startup> 
     <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
  </WebRole>


Now it is done ... You free to go with your cloud service


Enjoy 






Thursday, November 6, 2014

HttpClient Caching

Is any one of you have an experience on when send http request through http client the response become the same (no change) even your source of the response (server) is updated.

It is the way that default http protocol behaves

By default HttpClient use a cache to store responses that come up with response headers without Cache-Control header. ( Ref: HTTP Header fields)

In a scenario you need to change the cache behavior with HttpClient you can have two options

1. Edit the service (server) to response with relevant cache headers
2. Modify your request headers

Edit the service (server) to response with relevant cache headers

In this model it give two benefits to you
  • A content you will not use again is not stored in the client machine.
  • Other requests can benefit from the cache (when using the same instance of HttpClient).
In your web service go to web.config file and in-side the system.serviceModel add following tag with relevant headers you need


     <client>
      <endpoint address="http://localhost/..." >
        <headers>
          <Cache-Control>no-cache</Cache-Control>
        </headers>
      </endpoint>
    </client>


Modify your request headers

if you don't have the access to the server you can go with this option. Just ad additional header with HttpClient and send the request then response automatically include these headers

HttpClient Client = new HttpClient();
Client.DefaultRequestHeaders.Add("Cache-Control", "no-cache");


Now your HttpClient is ready to handle http request with no cache .


here is Cache contol values that provide from W3 with Http headers.

    cache-directive = cache-request-directive
         | cache-response-directive
    cache-request-directive =
           "no-cache"                          
         | "no-store"                          
         | "max-age" "=" delta-seconds         
         | "max-stale" [ "=" delta-seconds ]   
         | "min-fresh" "=" delta-seconds       
         | "no-transform"                      
         | "only-if-cached"                    
         | cache-extension                     
     cache-response-directive =
           "public"                               
         | "private" [ "=" <"> 1#field-name <"> ] 
         | "no-cache" [ "=" <"> 1#field-name <"> ]
         | "no-store"                             
         | "no-transform"                         
         | "must-revalidate"                      
         | "proxy-revalidate"                     
         | "max-age" "=" delta-seconds            
         | "s-maxage" "=" delta-seconds           
         | cache-extension 
 
 
 
 Enjoy the code .. 
 
 




Tuesday, July 15, 2014

Azure Mobile Services ( Start to build)

Windows Azure cloud application provide quite amazing solutions for Mobile backed services. With Azure cloud applications allows you to store structured data (files and SQL Azure) , Authentication interrogation to Mobile applications and user updates via push notifications. Specially Azure is not only for Windows (Microsoft ) Products. It supports Window 8, Windows Phone , Android and iOS with different development platforms such as native platforms and Xamarin.

Lets build first Cloud app

1. First Log in to your Azure Portal and click on New button in left corner













2. Then from prompt Select Compute -> Mobile Service-> Create

3. With the next prompt add URL for your Mobile service in URL field. With Database field if you have already created database for mobile application back end select it if it is not select option Create new SQL Database instance  or Create Free 20MB SQL Database Option

Select your region and what kind of backed you need to have. it has .NET and Javascript backed. Choose your choise

If you plan to include Push notification with your app tick on  Advanced Push Notification Check box













4. If you checked Advanced Push Notification Check box this step you find the Push Notification Settings prompt. Azure notification hub is cross platform push notification service that can simultaneously broadcast notifications across the devices.

Create namespace to notification service and name your push notification Hub























5. Then you can define the Database Settings. You can define new database name , If you already have database server select it or else create new database server and give the credentials for it as you want.
If you need to make advanced changes to the database tick on Configure Advanced Database Settings  Check box.

With Advanced database settings you can limit the database capacity and define the character encoding for the data














Then our web service is up and it take few seconds to configure and make it online













Once our Service is created the screen is like this












Select the platform that you need to create app that using this service and scroll down to to GET STARTED area.

Expand the Create new App. (this depend on what you select in Choose Platform Area Select the language C# or JavaScript and download the applicattion.

Run it and enjoy your first cloud app



Friday, July 11, 2014

REST in peace With Web services( from scratch )

REST  is stands for REpresentational State Transfer. REST is the underlying architecture of web.

It is basically the HTTP protocol, which was originally created to allow representational state transfer, not just transfer of web pages. HTTP is most commonly used to GET content and POST data. But it can also be used to PUT and DELETE data, as well as get Header information, etc

With this post I am going to create new web service that interact with data(xml) and going to make that web service into RESTFul web service

Create Web Service.  
 1. Open Visual Studio and goto -> New -> WCF -> WCF Service Application














2. Go to Solution explorer  and select two files IService1.cs and Service1.svc and delete them.(If you need you can keep them)















3. Then Press CTRL+SHIFT+A and Select Visual C# and WCF Service. Then give name for the service. Lets use it as demo_REST and Add














3. Lets open up the two files demo_REST.svc and demo_REST.cs and change its only funtion DoWork() to return string as output.

To do that first change the demo_REST.cs file's doWork as this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace REST_Demo
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "Idemo_REST" in both code and config file together.
    [ServiceContract]
    public interface Idemo_REST
    {
        [OperationContract]
        string DoWork();
    }
}


Then go to the demo_REST.svc and edit it as follow. Just need to  change return type and add code to middle

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace REST_Demo
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "demo_REST" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select demo_REST.svc or demo_REST.svc.cs at the Solution Explorer and start debugging.
    public class demo_REST : Idemo_REST
    {
        //change public void DoWork() to public string DoWork()
        public string DoWork()
        {
            //add return text
            return "Hello WCF";
        }
    }
}



now we are done with our simple WCF

run and test it ..

its open in WCF test Client from WCF test Client select the function that we create DoWork() amd click on it then click on invoke button to test it



 In Value column it will display the results .. its "Hello WCF" and our function is working..


Implementing data bound Web service 
I am not going details about databounded web services. My previous article Web service with DB interaction provided good demonstration about how to work with DB data.

Here I am going to bind the XML file with it. I got the xml data from W3Schools (http://www.w3schools.com/xml/cd_catalog.xml)


In Visual Studio CTRL+SHIFT+A  then select Data and select XML File  and name it as cd_data.xml then copy paste the XML data from W3Schools to the XML body.

Now cd_data.xml is look likes this
<?xml version="1.0" encoding="utf-8" ?>
!-- Edited by XMLSpy --><CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Greatest Hits</TITLE>
    <ARTIST>Dolly Parton</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>RCA</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1982</YEAR>
  </CD>
  <CD>
    <TITLE>Still got the blues</TITLE>
    <ARTIST>Gary Moore</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Virgin records</COMPANY>
    <PRICE>10.20</PRICE>
    <YEAR>1990</YEAR>
  </CD>
  <CD>
    <TITLE>Eros</TITLE>
    <ARTIST>Eros Ramazzotti</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>BMG</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1997</YEAR>
  </CD>
  <CD>
    <TITLE>One night only</TITLE>
    <ARTIST>Bee Gees</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1998</YEAR>
  </CD>
  <CD>
    <TITLE>Sylvias Mother</TITLE>
    <ARTIST>Dr.Hook</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS</COMPANY>
    <PRICE>8.10</PRICE>
    <YEAR>1973</YEAR>
  </CD>
  <CD>
    <TITLE>Maggie May</TITLE>
    <ARTIST>Rod Stewart</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Pickwick</COMPANY>
    <PRICE>8.50</PRICE>
    <YEAR>1990</YEAR>
  </CD>
  <CD>
    <TITLE>Romanza</TITLE>
    <ARTIST>Andrea Bocelli</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>10.80</PRICE>
    <YEAR>1996</YEAR>
  </CD>
  <CD>
    <TITLE>When a man loves a woman</TITLE>
    <ARTIST>Percy Sledge</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Atlantic</COMPANY>
    <PRICE>8.70</PRICE>
    <YEAR>1987</YEAR>
  </CD>
  <CD>
    <TITLE>Black angel</TITLE>
    <ARTIST>Savage Rose</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Mega</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1995</YEAR>
  </CD>
  <CD>
    <TITLE>1999 Grammy Nominees</TITLE>
    <ARTIST>Many</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Grammy</COMPANY>
    <PRICE>10.20</PRICE>
    <YEAR>1999</YEAR>
  </CD>
  <CD>
    <TITLE>For the good times</TITLE>
    <ARTIST>Kenny Rogers</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Mucik Master</COMPANY>
    <PRICE>8.70</PRICE>
    <YEAR>1995</YEAR>
  </CD>
  <CD>
    <TITLE>Big Willie style</TITLE>
    <ARTIST>Will Smith</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1997</YEAR>
  </CD>
  <CD>
    <TITLE>Tupelo Honey</TITLE>
    <ARTIST>Van Morrison</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Polydor</COMPANY>
    <PRICE>8.20</PRICE>
    <YEAR>1971</YEAR>
  </CD>
  <CD>
    <TITLE>Soulsville</TITLE>
    <ARTIST>Jorn Hoel</ARTIST>
    <COUNTRY>Norway</COUNTRY>
    <COMPANY>WEA</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1996</YEAR>
  </CD>
  <CD>
    <TITLE>The very best of</TITLE>
    <ARTIST>Cat Stevens</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Island</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1990</YEAR>
  </CD>
  <CD>
    <TITLE>Stop</TITLE>
    <ARTIST>Sam Brown</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>A and M</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Bridge of Spies</TITLE>
    <ARTIST>T'Pau</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Siren</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1987</YEAR>
  </CD>
  <CD>
    <TITLE>Private Dancer</TITLE>
    <ARTIST>Tina Turner</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>Capitol</COMPANY>
    <PRICE>8.90</PRICE>
    <YEAR>1983</YEAR>
  </CD>
  <CD>
    <TITLE>Midt om natten</TITLE>
    <ARTIST>Kim Larsen</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Medley</COMPANY>
    <PRICE>7.80</PRICE>
    <YEAR>1983</YEAR>
  </CD>
  <CD>
    <TITLE>Pavarotti Gala Concert</TITLE>
    <ARTIST>Luciano Pavarotti</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>DECCA</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1991</YEAR>
  </CD>
  <CD>
    <TITLE>The dock of the bay</TITLE>
    <ARTIST>Otis Redding</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Atlantic</COMPANY>
    <PRICE>7.90</PRICE>
    <YEAR>1987</YEAR>
  </CD>
  <CD>
    <TITLE>Picture book</TITLE>
    <ARTIST>Simply Red</ARTIST>
    <COUNTRY>EU</COUNTRY>
    <COMPANY>Elektra</COMPANY>
    <PRICE>7.20</PRICE>
    <YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Red</TITLE>
    <ARTIST>The Communards</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>London</COMPANY>
    <PRICE>7.80</PRICE>
    <YEAR>1987</YEAR>
  </CD>
  <CD>
    <TITLE>Unchain my heart</TITLE>
    <ARTIST>Joe Cocker</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>EMI</COMPANY>
    <PRICE>8.20</PRICE>
    <YEAR>1987</YEAR>
  </CD>
</CATALOG>


Now we need to have some method to access those data n service. Open demo_REST.cs and inside the interface Idemo_REST add operation contract we named it as GetCatalog(). and we are going to return catalog data as JSON string then our return type for the GetCatalog() should be string.

namespace REST_Demo
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "Idemo_REST" in both code and config file together.
    [ServiceContract]
    public interface Idemo_REST
    {
        [OperationContract]
        string DoWork();
        //our newly added operation contract.
        [OperationContract]
        string GetCatelog();
    }
}

Lets implement the logic behind that interface function in Open demo_REST.svc 
 Now its look like this


public class demo_REST : Idemo_REST
  {
      //change public void DoWork() to public string DoWork()
      public string DoWork()
      {
          //add return text
          return "Hello WCF";
      }
      /// <summary>
      /// Code behind the Operation contract
      /// </summary>
      /// <returns></returns>
      public string GetCatelog()
      {
          //Read the XML File.. *You need to give XML file as URL
          XDocument xmlDataSheet = XDocument.Load("http://localhost:55173/cd_data.xml");
          //Get all items in XML file to the code
          var allItems = from data in xmlDataSheet.Descendants("CD")
                         select new
                          {
                              Title = data.Element("TITLE").Value,
                              Artist = data.Element("ARTIST").Value,
                              Country = data.Element("COUNTRY").Value,
                              Company = data.Element("COMPANY").Value,
                              Price = data.Element("PRICE").Value,
                              Year = data.Element("YEAR").Value
                          };
          //Json Serializer initiation
          JavaScriptSerializer toJson = new JavaScriptSerializer();
          //convert the data in the xml to list and convert them as JSON string
          return toJson.Serialize(allItems.ToList());
      }
  }


Run and check Our new addition is working or not.

Make It RESTful

 With our Web service Most hard part is done and now we nee to make our web service as restful service. For easyness of understanding the REST I'm using string parameter to the GetCatelog()
method Now its look like GetCatelog(string Parameter) in both Open demo_REST.cs and Open demo_REST.svc files.

To make our web service REST enable we need to add Web Invoked functionality to service. Lets consider  the HTTP GET here.

//our newly added operation contract.
       //We need output as json and input text is as json and our GET Url is /GetCatelog?para=textInput
       //Make sure you add correct parameter to correct input when working with multiple parameters
       //You can try different methods
       [OperationContract]
       [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json,
          BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json,
          UriTemplate = "GetCatelog?para={Parameter}")]
       string GetCatelog(string Parameter);

Here is POST

[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "GetCatalog")]

Lets make it happen..

In final step you need to make sure few things configured correctly. configurations are on web.config file.

To make sure our endpoint of web service getting the JSON out put we need to add endpoint behavior to the web.config under <behaviors> tag

<!--End point json behavior-->
      <endpointBehaviors>
        <behavior name="jsonbehavior">
          <webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json"/>
        </behavior>
      </endpointBehaviors>

Under the <system.servicemodel> tag we need to add and configure our web service to enable HTTP (REST) and endpoint behaviors

<services >
    <!--adding service configuration-->
    <service name="REST_Demo.demo_REST"  >
      <endpoint
                address=""
                binding="webHttpBinding"
                behaviorConfiguration="jsonbehavior"
                contract="REST_Demo.Idemo_REST" />
    </service>
  </services>


We are done.. then run and test your service in browser
Here is my credentials. http://localhost:55173/demo_REST.svc/GetCatelog?para=text
 Result 






Full Code 
http://bit.ly/wcfREST