Solved

Returning JSON in a asp.net (vb) web service

Posted on 2012-03-19
5
1,238 Views
Last Modified: 2012-03-28
I've tried to return a JSON string from my asp.net (vb) webservice using something like this:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function Genex (ByVal id as String,ByVal type1 as Integer,ByVal xtext As string) As String

but I receive this error: "ScriptMethod is not defined".

If I include "Imports System.Runtime.Serialization" there is no JSON method or class.
How do I include it?

if I declare my WebMethod as:
<WebMethod()> _
Public Function Genex (ByVal id as String,ByVal type1 as Integer,ByVal xtext As string) As String

my webservice works fine but it responds with an XML string, I need that it responds with a JSON string
0
Comment
Question by:BemboX
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 100 total points
ID: 37740849
You need to add reference of System.Web.Extensions assembly in order ScriptMethod brings in a scrope
http://www.codeproject.com/Articles/45275/Create-a-JSON-WebService-in-ASP-NET-2-0-with-a-jQu
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37740981
0
 

Author Comment

by:BemboX
ID: 37753820
Do I need to install a library like json.net from json.codeplex.com or it is already included in the framework?
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 400 total points
ID: 37754265
when you specify your response format, it automatically serializes your response using Json Serializer, you can read more about it here:-

http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

so there is no need to install anything on service side.
0
 

Author Closing Comment

by:BemboX
ID: 37778527
Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question