A (JSONP) REST service with your existing WCF service

Datetime:2016-08-22 23:50:43         Topic: WCF  JSONP          Share        Original >>
Here to See The Original Article!!!

I'm mainly doing javascript in my free time, but at work, it's still classic .NET. Yesterday, I had to quickly set up a REST service via WCF to test something. In the spirit of saving my keystrokes , and for my own later reference, I'm posting how to do it here, instead of emailing it.
I'm assuming you have an existing WCF service.
Just add the following to your ServiceContract (you'll need a reference to System.ServiceModel.Web):
[WebGet(UriTemplate = "{id}", ResponseFormat = WebMessageFormat.Json)]
Person GetPerson(string id);
For REST to work, your parameters will have to be a string and you will have to parse it in the implementation of your ServiceContract.
I want JSONP , so I've added the response format and need some extra stuff in my config:
The service:
<endpoint address="People" 
    contract="My.Contracts.IPersonService" />
A behavior:
  <behavior name="jsonBehavior">
    <webHttp />
Finally, the binding:
  <binding name="Default" crossDomainScriptAccessEnabled="true" />


Put your ads here, just $200 per month.