views:

890

answers:

3

We are currently using a .asmx web service method which serializes our object to Json to be returned to the client and consumed by MS Ajax code. For some members of the object, we use custom converters via classes that derive from JavaScriptConverter and override the Serialize method. We "wire up" these custom converters in our web.config via the elements:

<system.web.extensions>
  <scripting>
    <webServices>
      <jsonSerialization maxJsonLength="2000000">
        <converters>
          <add name="ElementReference" type="OurNamespace.OurJavascriptConverter">

We are now changing over to a WCF web service. I am unable to find the WCF equivalent.

Thanks for any help.

+2  A: 

This might be what you're looking for http://blogs.msdn.com/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx.

Although it talks about REST, not sure if you're using WCF in that way. Might be usefule though, check it out.

Joshua Belden
A: 

By default, WCF uses DataContractSerializer in basic-http mode, and NetDataContractSerializer in some of the binary tcp modes. You can't really inject a converter per type/property, but you can replace the serializer by adding a "behavior" to the contract (at both ends). While possible, this isn't very portable, and you would be well advised to stick with the regular layout so that "mex" understands things correctly.

See here for an example of such a behavior.

AFAIK, the most likely alternative (for custom serialization) would be to implement IXmlSerializable and do everything yourself - not fun.

Marc Gravell
+3  A: 

One approach is to use the WCF raw programing model described by Carlos Figueria in combination with JSON.NET.

I've found JSON.NET to be far more flexible and configurable than the WCF JSON serializers.

dthrasher