Creating a .NET WCF 4.0 JSON Service

I had a lot of trouble getting configuring a .NET 4.0 WCF service which could be called from an HTML page using JQUERY.  The issue was pretty much all with configuring the service and so I thought I would share the web.config that I finally got that allowed the service to work properly.

First, ensure your service methods are decorated as shown:


    public interface ICommonService



        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]

        string[] GetData(string id);



Second, use this as a starting point for your web.config:

<?xml version="1.0"?>




    <customErrors mode="Off" />

    <compilation debug="true" targetFramework="4.0" />








          <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="true"/>




        <behavior name="MyServiceBehavior">

          <enableWebScript />





    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />



      <service name="MyJsonWcfService.Service1">

        <endpoint address="" behaviorConfiguration="MyServiceBehavior"

          binding="webHttpBinding" contract="MyJsonWcfService.IService1" >


            <dns value="localhost"/>









    <directoryBrowse enabled="true"/>

    <modules runAllManagedModulesForAllRequests="true"/>





Comments (2)
  1. Ralf says:

    Hi Mohammed, Care to share the JQuery code with us :D.

  2. madenwal says:

    Hey Ralf,

    I should have included this information but I didn't want to reinvent the wheel here.  I used this guide below to help me build the HTML source which I found very helpful. It was configuring the service to work properly with .NET 4.0 which I had a little difficulty. Here's the article:…/WCF_JQUERY_ASMX.aspx

Comments are closed.

Skip to main content