?
Solved

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

Posted on 2012-03-19
5
Medium Priority
?
1,400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 300 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
 

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 1200 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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