Here's the issue. I am using ASP.NET Web API integration with my project and I am storing the request URLs in the web.config. In my code, I use these URL to fire requests to the Web API and send and receive the data. The URLs are working fine, that I can assure you. The problem here is with this single URL.
Its working when I run both projects on local machine and the flow of data is proper. But when I test run it online after hosting, the same service fails to send me data. Instead, I receive the following exception in the catch block :
The remote server returned an error: (500) Internal Server Error.
I have already confirmed the following to be true and correct :
- The connection strings in both projects.
- No spelling mistakes.
- No incorrect URL.
- When debugging on local, it shows no error and proceeds successfully.
- Perfectly working on local and receiving proper data, only not working online.
I also tried re-hosting. But still the same. Not sure what could be the issue here.
Here is the controller method code :
using (var client = new WebClient())
{
Model serviceModel = new Model();
serviceModel.Number = Num;
serviceModel.type = "getalldetails";
client.Headers[HttpRequestHeader.ContentType] = "application/json";
JavaScriptSerializer serializer = new JavaScriptSerializer();
var result = client.UploadData(System.Web.Configuration.WebConfigurationManager.AppSettings["GetDetails"], Encoding.UTF8.GetBytes(serializer.Serialize(serviceModel)));//this is the exception point
}
This is the web.config URL:
<add key="GetDetails" value="http://hostname/api/controller/GetDetails" />
Also, I have error logs setup in the Web API side incase of a bad request or something like that, but no new record is inserted in this case. So this is leaving me confused so as to where the issue is.
This is what the exception is :
System.Net.WebException was caught HResult=-2146233079 Message=The remote server returned an error: (500) Internal Server Error.
Source=System StackTrace: at System.Net.WebClient.UploadDataInternal(Uri address, String method, Byte[] data, WebRequest& request) at System.Net.WebClient.UploadData(Uri address, String method, Byte[] data) at System.Net.WebClient.UploadData(String address, Byte[] data)