【问题标题】:Different Field serialization depends on set Accept type不同的字段序列化取决于集合接受类型
【发布时间】:2011-11-03 14:58:57
【问题描述】:

我有字段返回 System.Type 并且我知道它不可序列化。 So I want to implement own serialization this fields depends Accept type chosen by user for example if chosen Json serialization I want to return string name of javascript type supported by .net, and when choose xml serialization return string name of Xsd type supported by .net .

是否可以在 .net 类中包含此字段,或者在 IDispatchMessageInspector 或 IDispatchMessageFormatter 中更深入地执行此操作?

【问题讨论】:

    标签: wcf serialization


    【解决方案1】:

    为什么不将类型名称作为字符串(可序列化),然后在电线的另一端,将其转回Type

     Type t = Type.GetType(typeName);
    

    【讨论】:

    • 对我来说重要的是这个字符串不是 .net 类型名称,而是我可以在 switch(dotNetType){return xsdType;} 中选择的 xsd 或 javascript
    • 一般来说,最好的做法是让您的 WCF 服务尽可能具有互操作性。在这种情况下,Aliostad 的建议可以帮助您做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多