locked
Getting The remote server returned an error: (500) Internal Server Error RRS feed

  • Question

  • User-1564328985 posted

    I have written below code to send the SOAP XML request

    XmlDocument objSoapXML = new XmlDocument();

    objSoapXML.LoadXml(sSoapXML);

    HttpWebRequest objHttpWebRequest = (HttpWebRequest)WebRequest.Create(productURL);

    objHttpWebRequest.ContentType = "text/xml;charset=\"utf-8\"";

    objHttpWebRequest.Accept ="text/xml";

    objHttpWebRequest.Method ="POST";

    using (Stream objReqStream = objHttpWebRequest.GetRequestStream())

    {

    objSoapXML.Save(objReqStream);

    }

    // begin async call to web request.

    IAsyncResult objAsyncResult = objHttpWebRequest.BeginGetResponse(null, null);

    objAsyncResult.AsyncWaitHandle.WaitOne();

    string soapXMLResult;

    // get the response from the completed web request

    using (WebResponse objWebResponse = objHttpWebRequest.EndGetResponse(objAsyncResult))

    using (StreamReader objSteamReader = new StreamReader(objWebResponse.GetResponseStream())){

    soapXMLResult = objSteamReader.ReadToEnd();}

     When posting request for above service URL it is throwing "The remote server returned an error (500) internal server error". For the same URL from same machine it works fine from SOAPUI application. I could get successful response but above .NET code doesn't work. So what could be the issue. Any help will be apperciated.

    Thursday, August 9, 2012 8:16 AM

Answers

  • User-1662538993 posted

    Did you check that what could be the contenttype is?

    It could be text or json or anything else.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 10, 2012 9:29 AM

All replies

  • User-1662538993 posted

    I can see that you are tryint to call the service Asyncronocially.

    First try to do it just simple way and check if that is working fine.

    Check this link if you want to see the normal way of calling service -

    http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

    Thursday, August 9, 2012 10:35 AM
  • User-1564328985 posted

    I have implemented the code as suggessted by you but it started giving exception "The remote server returned an error: (404) Not Found" when tried to request.GetResponse().

    PLEASE NOTE: If I send same SOAPXML to below Service URL from same machine through SOAPUI 4.0.1, I get proper response.

       byte[] byteArray = Encoding.UTF8.GetBytes(sSoapXML);            
                WebRequest request = WebRequest.Create(sLookupURL);
                request.Credentials = CredentialCache.DefaultCredentials;
                request.Method = "POST";            
    
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = byteArray.Length;
    
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }
                // Get the response.
                using (WebResponse response = request.GetResponse())
                using (Stream responseStream = response.GetResponseStream())
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    Console.WriteLine(((HttpWebResponse)response).StatusDescription);
                    // Get the stream containing content returned by the server.
    
                    string responseFromServer = reader.ReadToEnd();
                    // Display the content.
                    Console.WriteLine(responseFromServer);
                }

    Friday, August 10, 2012 4:17 AM
  • User-1662538993 posted

    So then it could be network related issue like firewall or some kind of permission related.

    Check with your admin or if it is hosted on shared server then check with them.

    Friday, August 10, 2012 9:11 AM
  • User-1564328985 posted

    I too suspected the same issue but from the same machine if fire SOAP request thorugh SOAPUI 4.0.1 tool for same service URL, it works perfectly fine. I get proper response.

    Friday, August 10, 2012 9:16 AM
  • User-1662538993 posted

    Did you check that what could be the contenttype is?

    It could be text or json or anything else.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 10, 2012 9:29 AM
  • User-1181415477 posted

    Are you able to figure out the issue ? I am also getting the same error . When WEB API making Post call to other WEB API

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
    request.Method ="POST";
    request.ProtocolVersion = HttpVersion.Version11;
    request.Accept ="application/json";
    request.ContentType ="application/json";
    request.Credentials =CredentialCache.DefaultCredentials;
    request.GetRequestStream().Write(new System.Text.UTF8Encoding().GetBytes(data), 0, data.Length);

    return request.GetResponse();

    both web api are windows authentication enabled.

    Throwing : "The remote server returned an error: (404) Not Found"

     

     

    Thanks in advance

    Ram

    Thursday, October 3, 2013 5:42 PM