Simplest way to expose a JSON service in ASP.NET / DotNetNuke
See the question and my original answer on StackOverflowWCF (I think starting with version 3.51) has a nice "zero config" feature that integrates easily with IIS. All you have to do is
- create a JSON aware interface & service
- create a simple .SVC file in the IIS site.
You don't need to mess with funky .config
files :-)
Example .SVC file:
<%@ ServiceHost
Service="MyNamespace.MyService"
Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Example interface & service implementation, something like this:
public class MyService : IMyService
{
public string Test(string text)
{
return text; // whatever
}
}
[ServiceContractAttribute(Namespace="http://schemas.myservice.com")]
public interface IMyService
{
[OperationContractAttribute]
[WebInvokeAttribute(UriTemplate="Test", // change this accordingly
ResponseFormat=WebMessageFormat.Json, // change this accordingly
RequestFormat=WebMessageFormat.Json, // change this accordingly
BodyStyle=Wrapped)]
string Test(string text);
}
Here is an extra cool link about all this: WCF Web Services The Easy Way.