Search code examples
.netjsonc#-4.0wcf-data-services

How to remove "d" wrapper from WCF Data Service using EF4


My question is similar to this one JsonConvert.DeserializeObject and "d" wrapper in WCF but I'm not sure how to implement this for my situation. Here is my complete web.config the WCF Data Service:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<location path="MyWcfDataService.svc">
    <system.web>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>

    <system.serviceModel>
      <behaviors>
        <endpointBehaviors>
          <behavior name="MyWcfDataServiceBehavior">
            <webHttp defaultOutgoingResponseFormat="Json"/>
          </behavior>
        </endpointBehaviors>
      </behaviors>
    </system.serviceModel>
</location>

</configuration>

My Data Service is simple enough:

// specifying WebMessageBodyStyle.Bare doesn't seem to have any effect
[WebGet(ResponseFormat = WebMessageFormat.Json, 
    RequestFormat = WebMessageFormat.Json, 
    BodyStyle=WebMessageBodyStyle.Bare)] 
public string GetJsonTest(string x)
{

    var json = new
    {
        hello = "world"
    };

    return new JavaScriptSerializer().Serialize(json);
}

Solution

  • As far as I can tell, it is impossible to remove the 'd'. It is built into Data Services for security reasons.