开发者

ASP.Net Webservice Serialization

开发者 https://www.devze.com 2023-01-05 13:38 出处:网络
Could someone here point me in the right direction about how I can override the serialization that occurs when my webservice is called?

Could someone here point me in the right direction about how I can override the serialization that occurs when my webservice is called?

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.

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

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: 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))


You can use Stream or Message classes as return types, then you can implement your custom serialization. See for example How to set Json.Net as the default serializer for WCF REST service as an example.

0

精彩评论

暂无评论...
验证码 换一张
取 消