Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Web service method return JSON text without XML tags

Posted on 2009-05-06
2
Medium Priority
?
870 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 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

715 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