title: ResponseFormat.Json returns xml
body: <p>i know im not the first with this problem, but i cant seem to find a working solution</p>
  
  <p>when using a webservice set to return json, .net still wraps it in an XML wrapper.</p>
  
  <p>i searched and tried many things</p>
  
  <ol>
  <li>i tried adding various httphandler settings to my web.config, as suggested in certain posts, but these had no effect. also i don't think its necessary as im working on  a brand new win7/iis7.5/.net4 box. i read that since .net 3.5 there shouldn't be any problem. but there is!</li>
  <li>i tried with and without the responseformat.json decoration. my webservice returns valid json ( i can parse it with parsejson, after extracting the string)</li>
  <li>i tried explicitly setting the contenttype and datatype. this causes an error complaining that the response was invalid json. which is right!</li>
  </ol>
  
  <p>what is happening is very confusing, in IE , at least on my devbox, the response returns as an xml document where i can just use msg.text and easily get the json string, but in production i tested in FF and it returns as a document, with no "text" property.</p>
  
  <p>heres my javascript/jquery</p>
  
  <pre><code>$.ajax({
  error: function (xhr, ajaxOptions, thrownError) {
      alert(xhr.status+'-'+xhr.statusText);
      alert(thrownError);
      },
      url: '&lt;%=ResolveUrl("~/WebService.asmx")%&gt;' + "/JackJill",
      contentType: "application/json",
      success: function (msg) {
          alert(msg.d); 
      }
  });
  </code></pre>
  
  <p>so: how can i simply ask .net to return a valid regular json string, instead of wrapping it. i believe that will solve all the problems. it will also make my service more accessible to the world at large, so they don't have to do any special parsing.</p>
  
  <p>thank you very much for any advice or pointers</p>
  
  <p>sincerely</p>
  
  <p><strong>EDIT:</strong>
  heres a sample webservice that i just tested:</p>
  
  <pre><code>&lt;ScriptMethod(ResponseFormat:=ResponseFormat.Json)&gt; &lt;WebMethod()&gt; Public Function JackJill() As String
      Return "[{""Name"":""Jack""},{""Name"":""Jill""}]"
  End Function
  </code></pre>
  
  <p>then when i put this in the browser</p>
  
  <p><a href="http://localhost:81/webservice.asmx/JackJill" rel="noreferrer">http://localhost:81/webservice.asmx/JackJill</a></p>
  
  <p>i get</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;string xmlns="http://tempuri.org/"&gt;
  [{"Name":"Jack"},{"Name":"Jill"}]
  &lt;/string&gt; 
  </code></pre>
  
  <p>why all this xml stuff here?</p>