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
}






Technology
published
v.0.01




© 2024 - ErnesTech - Privacy
E-Commerce Return Policy