Last post Sep 18, 2009 03:31 PM by jcard
Feb 16, 2006 10:18 PM|ttdbn|LINK
I want to have my webservice return "Hello World" without the XML element tags shown below that it returns by default. Thanks in adavnce.
Feb 17, 2006 09:16 AM|idof|LINK
The answer to you question is - You can't do it in ASP.NET web services !
However, if you build your own listener, instead of using .NET's web services and IIS, you will be able to return what ever you want - but that will make you web service not compatible with the W3C.
The following url is to a sample application shown by Clemens Vasters (http://staff.newtelligence.net/clemensv) in a .NET session held in Israel a few months ago :
In the above sample, you can find different ways to create a service - one of the ways is by creating a listener.
Best of luck,
Feb 18, 2006 04:28 AM|bnye|LINK
Thats a bummer. Is there no way to output JSON from a .net webservice? Would something like bitkraft work so that we don't have to reinvent the wheel?
Feb 18, 2006 10:01 AM|sparky62|LINK
May 11, 2009 05:07 PM|WesSmith|LINK
May 11, 2009 07:09 PM|johnwsaunders3|LINK
Were you aware that ASMX web services are not the current .NET Web Services technology? You are hacking workarounds to make old technology do things it was not designed for. Instead, I strongly suggest you start learning about WCF. Any new features - like
support for REST are much more likely to be made available on WCF than on ASMX.
In fact, I believe you'll find that what you're looking for is already available in WCF.
Jun 19, 2009 02:08 PM|rchesney01|LINK
How about simply:
public void HelloWorld()
Jun 19, 2009 05:40 PM|johnwsaunders3|LINK
I don't know. Did you try it, and did it work?
Sep 18, 2009 03:31 PM|jcard|LINK
I think there's a gap in your understanding. It looks like youre writing a [WebMethod] that returns a string and then youre forming a string that looks like XML (not "Hello World") and sending it back, hence your comment about "adding an xml tag" - adding
a tag doesnt confuse most parsers, but sending XML that is expected wrapped in a tag that is not, will break things.
Essentially youre looking for a way to write the string "<?xml version=1.0?><blah><a>b</a></blah>" to the response and are complaining about what is being added, but you have to understand that it is the XML serializer that is adding tags so that the response
string can be represented as a string
Instead you should be making a Blah OBJECT with an A property that serializes itself as you want, and stating THAT OBJECT to be the return type of your method. Thus, the serializer comes along and finds a Blah object being returned (not a preformatted string)
and serializes it accordingly. If you return a string, the serializer will return an xml representation of a string.
I can't think of any way to explain this other than maybe: what is 1 + 2 ?
What is "1" + "2" ?
Strings and numbers here behave differently, within the sematic of the language. In the same way the serialization of returned responses behaves differently; the serializer cannot know that your string contains exactly the xml you want to return any more
than the language can know that you want "1" + "2" to be "3", or that a string of "24-Jul-1990" is your birthday; it just sees text and encodes text in its own way.
If you want encoded text to come out in a certain way, you have to feed data in in a way that will cause it to appear thus. I.e. you have to feed in a
new Blah().a = "b" object so that it will make "<blah><a>b</a></blah>" out of it