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

  • Question

  • User-776477372 posted

    i am working in wcf service. 

    System.Net.HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://abc.com/");
    request.Credentials = CredentialCache.DefaultNetworkCredentials;

    // Prevents framework from searching proxy configuration, 
    // hence removes a long delay on the first request.
    //
    request.Proxy = null;
    request.Method = "POST";
    request.ContentType = "text/xml; charset=utf-8";

    // Find service identification based on query content
    //
    String query_type = "";
    for (int i = 0; i < service_query.Length; i++)
    {
    String query_str = service_query[i];
    String query_id = service_mappings[i];

    if (query.IndexOf(query_str) != -1)
    query_type = query_id;
    }

    // Set SOAP Action (uses wsap name and query type determined above)
    //
    request.Headers.Add("SOAPAction:\"http://webservices.abc.com/" + wsap + "/" + query_type + "\"");

    String final_query = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";

    // If not authenticating... add session data
    //
    if (query_type.Length < 21 || query_type.Substring(0, 21) != "Security_Authenticate")
    {
    final_query += "<s:Header>";
    final_query += "<aws:SessionId xmlns:aws=\"http://webservices.abc.com/definitions\">" + session + "</aws:SessionId>";
    final_query += "</s:Header>";
    }
    final_query += "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
    final_query += query;
    final_query += "</s:Body>";
    final_query += "</s:Envelope>";

    // Encode request in UTF-8
    //
    byte[] query_byte = Convert(final_query, Encoding.UTF8.GetEncoder());
    request.ContentLength = query_byte.Length;

    // Send request
    //
    Stream request_stream;
    try
    {
    request_stream = request.GetRequestStream();
    }
    catch (Exception e)
    {
    Console.Out.WriteLine("Cannot get HTTP request stream: " + e.Message);
    if (e.InnerException != null)
    {
    return e.InnerException.Message;
    }
    return e.Message;
    }

    request_stream.Write(query_byte, 0, query_byte.Length);

    // Get response
    //
    HttpWebResponse response = null;
    try
    {
    response = (HttpWebResponse)request.GetResponse();
    }
    catch (Exception e)
    {
    // Manage HTTP ERROR 500...
    //
    Console.Out.WriteLine("Cannot get HTTP response: " + e.Message);

    FieldInfo fi = request.GetType().GetField("_HttpResponse", BindingFlags.NonPublic | BindingFlags.Instance);
    if (fi != null)
    {
    response = (HttpWebResponse)fi.GetValue(request);
    }
    if (response == null)
    {
    request_stream.Close();
    if (e.InnerException != null)
    {
    return e.InnerException.Message;
    }
    return e.Message;
    }
    else
    {
    Console.Out.WriteLine("Got response data (HTTP 500 - SOAP FAULT)");
    }
    }

    // Get response stream...
    //
    Stream response_stream = response.GetResponseStream();

    StreamReader sr = new StreamReader(response_stream);
    String result = sr.ReadToEnd();
    sr.Close();

    request_stream.Close();
    response_stream.Close();

    return result;

    -----------------------

    and getting error : The remote server returned an error: (500) Internal Server Error.

    Saturday, March 16, 2013 3:32 AM

All replies