Posted By

guru2015 on 09/18/14


Tagged

api client web-server c#


Versions (?)

web api client getting the Remote server returned an error:500


 / Published in: C#
 

URL: none

I have completed my code my its giving me The remote server returned an error: (500) Internal Server Error. I been trying with Get and Post method but not luck, can anyone help me to view what I could doing wrong? Here you have my code, as you can see in comments I have tried several thing but nothing work This is an important project for me and I been looking everywhere and I have no luck.

Thanks

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net.Http;
  10. using System.Threading.Tasks;
  11. using System.IO;
  12. using System.Web;
  13. using System.Net;
  14.  
  15.  
  16.  
  17. namespace DisplayDataInformation
  18. {
  19. public partial class DisplayDataInformation : Form
  20. {
  21. public DisplayDataInformation()
  22. {
  23. InitializeComponent();
  24.  
  25. }
  26.  
  27. private void Submit(object sender, EventArgs e)
  28. {
  29. localhost.Dashboard proxy = new localhost.Dashboard();
  30. localhost.MetaData[] pm = proxy.GetAllMetaData();
  31. //const string MyProgramURL = "http://localhost/MyProgramm/";
  32. const string apiKey = "MyKey123";
  33. const string ProgramId = "user1";
  34. const string ProgramPass = "123456";
  35.  
  36.  
  37. HttpWebRequest myHttpWReq;
  38. HttpWebResponse myHttpWResp;
  39.  
  40. // myHttpWReq.ContentType
  41.  
  42. // Make a web request to the web service
  43. myHttpWReq = (HttpWebRequest)System.Net.WebRequest.Create("http://localhost/MyProgram/Dashboard.asmx/GetAllMetaData" + apiKey + ProgramId + ProgramPass);
  44.  
  45. myHttpWReq.Method = "Post";
  46. //myHttpWReq.Method = "Get";
  47.  
  48. myHttpWReq.ContentLength = 0;
  49.  
  50. // Get the response of the web service
  51. myHttpWResp = (HttpWebResponse)myHttpWReq.GetResponse();
  52.  
  53. if (myHttpWResp.StatusCode == HttpStatusCode.OK)
  54. {
  55. //Create an XML reader to parse the response
  56. System.Xml.XmlReader reader = System.Xml.XmlReader.Create(myHttpWResp.GetResponseStream());
  57.  
  58. }
  59.  
  60. //set an string output to the windows form
  61. StringBuilder sb = new StringBuilder();
  62.  
  63.  
  64. foreach (localhost.ProjectMetaData value in pm)
  65. {
  66. sb.AppendLine(value.ProjectTitle + " - "
  67. + value.ProjectID + " - "
  68. + value.PublishStatus);
  69.  
  70. }
  71.  
  72. label1.Text = sb.ToString(); //some label on your form for output
  73.  
  74. }
  75.  
  76. }
  77. }

Report this snippet  

You need to login to post a comment.