How to return JSON from a 2.0 asmx web service?

It's no problem to return JSON from ASMX services in ASP. NET 2.0 You just need the ASP. NET AJAX Extensions installed.

It's no problem to return JSON from ASMX services in ASP. NET 2.0. You just need the ASP.NET AJAX Extensions installed.

Do be sure to add the ScriptService decoration to your web service. That's what instructs the server side portion of the ASP.NET AJAX framework to return JSON for a properly formed request. Also, you'll need to drop the ".

D" from "msg. D" in my example, if you're using it with 2.0. The ".

D" is a security feature that came with 3.5.

You need to decorate your web method with the following: ScriptMethod(ResponseFormat = ResponseFormat. Json) You've got the rest right :) More info at Encosia and Andrew Roland's Blog EDIT: As noted below this is . NET 3.5 only (I was unaware of this, my bad).

1 The 'ResponseFormat' enumeration is only supported from 3.5 onwards, OP asked how to do in FW 2.0. – Kev? Nov 14 '08 at 1:19 @Kev what is OP?

– Chuck Norris Jun 16 at 12:39 1 @Omu Original Poster as in the person who asked the question (or in forums the person who started the thread) – Darko Z Jun 17 at 0:54.

You probably can't do anything other than XML or binary serialization in . NET 2.0. If you're not using an autogenerated web reference then don't bother with ASMX.

Just use an ASPX or ASHX instead.

1 ASHX is your answer – John Sheehan Nov 14 '08 at 5:52.

You can use the Jayrock library Quick start for asp. Net This allows you to write a http handler to return you json. Namespace JayrockWeb { using System; using System.

Web; using Jayrock. Json; using Jayrock. JsonRpc; using Jayrock.JsonRpc.

Web; public class World : JsonRpcHandler { JsonRpcMethod("greetings") public string Greetings() { return "Welcome to Jayrock! "; } } }.

I actually looked at that as a possible solution, if I couldn't do it with plain 'ol asp.net. Thanks. – camainc Nov 14 '08 at 14:28.

I may not be 100% correct on this but I'm sure . Net webservices are XML/SOAP based. You would need to override the default behavior of the webservice.

I'm not entirely sure that this would even be possible. I know this won't be the most useful answer, but may get you headed in the right direction.

See the answers to my question: ASP. NET - What is the correct approach to JSON based web services with jQuery?

The response is wrapped in a element because you're method says it will return a string. You could use this to be able to send plain json, but your wsdl will be fooled (the function is void but does respond data). WebMethod(Description="return pure JSON") public void retrieveByIdToPureJSON( int id ) { Context.Response.

Write( JsonConvert. SerializeObject( mydbtable. GetById(id) ); } Good luck, tom Btw: see Newtonsoft.

Json for JsonConvert.

It's also possible to just write up your own quick JSON converter using Refelction. Dim sb As New StringBuilder("{") For Each p As PropertyInfo In myObject.GetType().GetProperties() sb. Append(String.

Format("""{0}"":""{1}"",", p. Name, p. GetValue(myObject, Nothing).ToString())) Next p //remove the last "," because it's uneeded.Sb.

Remove(sb. Length - 1, 1) sb. Append("}").

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions