Hi Everyone,
I am new to consume a Web service through HttpWebRequest.So i create a dummy application for learning purpose.My question may be silly but answers would be appreciated.
I have created a demo web service, Below is the code
[WebMethod]
public DataSet GetEmployees()
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["FAST"].ConnectionString);
SqlCommand cmd = new SqlCommand("select * from Employee", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
Here i am returning DataSet and i want to bind it in GridView in my client Application.
The Below are the Client application code
string url = "http://localhost:2018/EmployeeService.asmx";
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(url);
webreq.ContentType = "text/xml; charset=utf-8";
webreq.Headers.Clear();
webreq.Method = "POST";
Encoding encode = Encoding.GetEncoding("utf-8");
HttpWebResponse webres = null;
webres = (HttpWebResponse)webreq.GetResponse();
Stream reader = null;
reader = webres.GetResponseStream();
StreamReader sreader = new StreamReader(reader, encode, true);
string result = sreader.ReadToEnd();
While running i am getting error "
The remote server returned an error: (500) Internal Server Error." in this line, webres = (HttpWebResponse)webreq.GetResponse();
Anyone have any idea where i did mistake.