Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

Consume Web Service in Webform

$
0
0

Hi,

I have a web form application that needs to receive SQL Query result from a SOAP web server or a Restful WEB API.

The web application gets the service URL from a text file (which can be different from customer to customer).

I need to find a generic backend solution (c#) to consume the service.

I tried using the following code, but it only works for the Web API service since I am reading Json format which serializes a multidimensional array, and I can't return a multidimensional array with web services:

String jsonData;
////REST WEB API            //string url =             //    String.Format(            //        @" http://localhost:52969/api/SQL?idx=" + TextBox1.Text);
////SOAP WEB SERVICE            string url =                String.Format(                    @" http://localhost:52358/TestWebService.asmx?op=Get");            System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);            using (System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse())            {                using (System.IO.Stream stream = response.GetResponseStream())                using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))                {                    jsonData = reader.ReadToEnd();                }                Label1.Text = jsonData;                                string[,] deserialized = JsonConvert.DeserializeObject<string[,]>(jsonData);                            }

Is there a way to force the WEB SERVICE to return a JSON output without all the unnecessary tags?

If not, how can I consume a web service/ web api that returns XML results from backend? all using the same code.

 


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>