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.

4

3 回答 3

3

一种方法是将Carlos Figueria 描述的WCF 原始编程模型与JSON.NET结合使用。

我发现 JSON.NET 比 WCF JSON 序列化程序更加灵活和可配置。

于 2009-05-03T16:13:27.090 回答
2

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.

于 2009-04-30T15:08:13.730 回答
0

默认情况下,WCF 使用DataContractSerializer基本 http 模式和NetDataContractSerializer一些二进制 tcp 模式。您不能真正为每个类型/属性注入转换器,但您可以通过在合同中添加“行为”(在两端)来替换序列化程序。虽然可能,但这不是很便携,建议您坚持使用常规布局,以便“mex”正确理解事物。

有关此类行为的示例,请参见此处。

AFAIK,最可能的替代方案(用于自定义序列化)是自己实现IXmlSerializable和做所有事情 - 不好玩。

于 2009-05-01T13:19:05.590 回答