Solved: How NOT To Show XML In Json Returned By ASMX WebService

Problem:
Returning pure JSON when using SMX web service is somehow critical to passing data from the server to the client (Mobile Phones, Websites etc).
For almost six months I have had a problem where I did not want JSON to be returned wrapped up in XML strings for example: 

 xmlns="http://tempuri.org/">
"[{\"OrderId\":2,\"UserId\":null,\"FirstName\":\"Mack\",\"LastName\":\"Erick\",\"Phone\":\"218-098-

This created problems when trying to call the API using angularJS when JSON has to be returned and read in a promise. The error that was thrown was Cannot Read Data At Position 0 >. 

Solution:
How I solved this annoying problem is by synthesizing the function in the Webservice so that it does not return a String, instead to have Void defined
Public void NameOfFunction(String API_Key){
//DoSomthing In Here
//Check For API and Logic
//Do not return anything (Its Void)
Then the breakthrough came
//Convert Object/String/Data to JSON
//Just write the context Response
Context.Response.Write(JsonObJect Or String Or Whatever value you want)
//Then just call the function from the website or an App
}






Edit this Article
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy