Solved

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

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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