ASP.Net web服务序列化 [英] ASP.Net Webservice Serialization
问题描述
有人能在这里指出我在正确的方向,我怎么可以改写发生在我的web服务被称为序列化?
Could someone here point me in the right direction about how I can override the serialization that occurs when my webservice is called?
基本上最终的结果我的目标是为追加一个TIMESTAMP对所有对象从我的web服务返回,但只有当我的web服务所使用的的JavaScriptSerializer,而不是XML序列化。
Basically the end result I am aiming for is appending a TIMESTAMP to all objects returned from my webservice but only when the JavascriptSerializer is being used in my webservice as opposed to the XML serializer.
因此,例如,下面是包含在我的web服务的方法。
So for example below is a method that is contained in my webservice.
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function GetSettingData(ByVal Username As String, ByVal Password As String) As SettingList
在web服务在某一点上的JavaScriptSerializer调用调用(作为一个GET请求)和我对象分析和JSON输出。我假设的地方,invokation的时候,我可以将我自己的JavaScriptSerializer的版本,并根据需要做什么?
When the webservice is called (As a GET request) at some point the JavascriptSerializer is invoked and my objects parsed and outputted as JSON. I am assuming that somewhere during that invokation I can insert my own version of the JavascriptSerializer and do as required?
任何人都可以在这里指导我?
Anyone able to guide me here?
(PS:我很清楚地知道,我可以从我所有的web服务返回字符串,并根据需要在实际的webmethod呼叫,但我正在寻找一个'好'的解决方案,那么这(除了这将意味着我需要执行序列不同的方法,如果我想返回XML))
(PS: I am well aware that I can return strings from all my webservices and perform the serialization as required in the actual webmethod call but I am looking for a 'better' solution then that (besides that would mean I would need different methods if I wanted to return XML))
推荐答案
您可以使用流
或消息
班作为返回类型,那么你可以实现你的自定义序列化。例如,见<一href=\"http://stackoverflow.com/questions/3118504/how-to-set-json-net-as-the-default-serializer-for-wcf-rest-service/3131413#3131413\">http://stackoverflow.com/questions/3118504/how-to-set-json-net-as-the-default-serializer-for-wcf-rest-service/3131413#3131413例如,
You can use Stream
or Message
classes as return types, then you can implement your custom serialization. See for example http://stackoverflow.com/questions/3118504/how-to-set-json-net-as-the-default-serializer-for-wcf-rest-service/3131413#3131413 as an example.
这篇关于ASP.Net web服务序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!