Solved

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

Posted on 2012-03-19
5
1,185 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now