Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to create and call the web service created. But i am not able to get the response. Getting remote internal server 500 error on calling the same


Url called- [^]

What I have tried:

private void sample()
       {
           try

           {
               string requestUrl="http://ntp-434:95/WebService1.asmx?op=HelloWorld";

               WebRequest request = WebRequest.Create(requestUrl);
               // Set the Method property of the request to POST.
               request.Method = "POST";

               // Create POST data and convert it to a byte array.
               string postData = "This is a test that posts this string to a Web server.";
               byte[] byteArray = Encoding.UTF8.GetBytes(postData);
               // Set the ContentType property of the WebRequest.
               request.ContentType = "application/x-www-form-urlencoded";
               // Set the ContentLength property of the WebRequest.
               request.ContentLength = byteArray.Length;

               // Get the request stream.
               Stream dataStream = request.GetRequestStream();
               // Write the data to the request stream.
               dataStream.Write(byteArray, 0, byteArray.Length);
               // Close the Stream object.
               dataStream.Close();

               // Get the response.
               WebResponse response = request.GetResponse();
               // Display the status.
               Console.WriteLine(((HttpWebResponse)response).StatusDescription);
               // Get the stream containing content returned by the server.
               dataStream = response.GetResponseStream();
               // Open the stream using a StreamReader for easy access.
               StreamReader reader = new StreamReader(dataStream);
               // Read the content.
               string responseFromServer = reader.ReadToEnd();
               // Display the content.
               Console.WriteLine(responseFromServer);
               // Clean up the streams.
               reader.Close();
               dataStream.Close();
               response.Close();
           }
           catch(Exception ex)
           {

           }
       }
Posted
Updated 22-Apr-18 22:22pm
v2
Comments
Richard MacCutchan 23-Apr-18 4:26am    
You need to contact the owners of the server to find out what went wrong.
Patrice T 23-Apr-18 4:29am    
Have remote server fixed.
GKP1992 23-Apr-18 4:53am    
Debug your web-service. You can use Postman to call the service without having to write code for it.
johannesnestler 23-Apr-18 10:23am    
You have to search for the error on server-side, isn't that obvious? If you say the same call works first and then you get the error a good guess would be a problem with async call handling on server side...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900