WCF/WF - Difference between a http web request/response with respect to web request /response

Asked By karur krishna madhu on 12-Feb-14 08:55 AM
I have a web service hosted in a server and i am trying to invoke a web method that takes 3 parameters . i created the web reference using the wsdl and with the proxy  i had to pass the url with the method name  to http request (url)and then i have to obtain the http web response . when i did this it threw an error"  5oo error an internal error in the server.

but when i replaced http web request class with that of web  request/response class. then i got the xml data out put perfectly.

what is the diff in http web request/response and normal web request and response ? when to use what?
Robbe Morris replied to karur krishna madhu on 12-Feb-14 09:02 AM
You'd have to post your code before anyone can review what you did wrong.
karur krishna madhu replied to Robbe Morris on 13-Feb-14 04:28 AM

  WebRequest request = HttpWebRequest.Create("http://localhost:5483/WebService2.asmx");

        request.Credentials = CredentialCache.DefaultCredentials;

        byte[] bytes;

        bytes = System.Text.Encoding.ASCII.GetBytes("ecoId=12246&aiId=1&action=test&comment=test");

        //Set HttpWebRequest properties

        request.Method = "POST";

        request.ContentLength = bytes.Length;

        request.ContentType = "text/xml; encoding='utf-8'";

 

        //Sends the HttpWebRequest, and waits for a response.

      

      using (WebResponse response = request.GetResponse())

        {

          using (StreamReader reader = new StreamReader(response.GetResponseStream()))

          {

            string urlText = reader.ReadToEnd();

            //Do whatever you need to do

          }

        }

Robbe Morris replied to karur krishna madhu on 13-Feb-14 08:40 AM
Don't set the request.ContentLength