0

I have asp.net web service. The web service has url like this:
mydomain dot com/service.asmx/getlocation?id=100

I always get below error. I tried both synchronous and async ways. I even tried to use Google.com but I always get below error:

Unhandled Exception:

System.Net.WebException: The remote server returned an error: (500) Internal Server Error.

My code looks like this:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.ContentType = "application/json";
request.Timeout = 60000;
request.Method = "GET";

// I get error here 
using (WebResponse response =  request.GetResponse())
{
    // Get a stream representation of the HTTP web response:
    using (Stream stream = response.GetResponseStream())
    {
        // Use this stream to build a JSON document object:
        JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
        Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());

        // Return the JSON document:
        return jsonDoc;
    }
}

Thanks

Edit:

I tried it on different emulators- Nexus 7 Lollipop(5.1.0) and Nexus S(4.4.2)

I.G. Pascual
  • 5,818
  • 5
  • 42
  • 58
Mac
  • 25
  • 6
  • 2
    HTTP 500 means that it is a problem that occurred on the web service itself. It might be caused by lack of error handling due to bad input. – jegtugado May 24 '16 at 07:37
  • I m using web service like a url. Is it bad approach? Also, the input to web service is not bad, I can print url and check in browser and it shows me correct result while with my app, it is throwing error – Mac May 24 '16 at 07:47
  • Try this approach, just to make sure the problem in in the web service not how the client is set up. [Top answer of this question](http://stackoverflow.com/questions/7510953/calling-asmx-from-c-sharp-server-side-endpoint-element-matching-this-contract-c) although error 500 is pretty clear. – pvxe May 24 '16 at 08:00
  • Also noticing... It seems that returning JSON from a SOAP Service is quite tricky, I have looked at this stackoverflow question [How to let an ASMX file output json](http://stackoverflow.com/questions/211348/how-to-let-an-asmx-file-output-json) – pvxe May 24 '16 at 08:15
  • You can use Newtonsoft.Json api. – Akash Amin May 24 '16 at 08:19
  • Thanks @JoséMaría Your help solved my problem. – Mac May 24 '16 at 21:07
  • Ok, do you mind if I put that as a answer and you mark is as correct? For the sake of correctness when people look at this question in the future. – pvxe May 25 '16 at 06:03

0 Answers0