Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
A short film showing how OnPage and Connectwise integration works.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

919 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

21 Experts available now in Live!

Get 1:1 Help Now