Solved

Web service method return JSON text without XML tags

Posted on 2009-05-06
2
868 Views
Last Modified: 2012-05-06
How can I create a webmethod in a web service that returns only text without the XML?  

Here is my code:
public class Services : System.Web.Services.WebService {
    [WebMethod]
    public string Sample()  {
        return "I want only text.";
    }

Current Result:
<?xml version="1.0" encoding="utf-8" ?>
  <string xmlns="http://tempuri.org/">I want only text.</string>

Desired Result:
"I want only text."

Thanks.
0
Comment
Question by:ktmedlin
[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 Comments
 
LVL 9

Accepted Solution

by:
tculler earned 500 total points
ID: 24322723
You could do something similar to the following code snippet. There are other ways, but this seems simplest.
static System.String GetInnerText(System.String myFullText)
{
     Int32 start = myFullText.IndexOf('>') + 1;
     return myFullText.Substring(start, myFullText.LastIndexOf('<') - start);
}

Open in new window

0
 

Author Comment

by:ktmedlin
ID: 24332262
Well since ASP.Net web services use SOAP I guess the only way to get a valid JSON string is to strip out the XML as you suggested.  Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

617 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