Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Code in desktop application :

C#
private void button3_Click(object sender, EventArgs e)
        {
            // Postvars
            byte[] buffer = Encoding.ASCII.GetBytes("test=postvar&test2=another");
            //byte[] buffer = Encoding.ASCII.GetByteCount(label1.Text);
            //Initialization, we use localhost
            HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://127.0.0.1/MyWebS.asmx");
            //Our method is post, otherwise the buffer (postvars) would be useless
            WebReq.Method = "POST";
            //We use form contentType, for the postvars.
            WebReq.ContentType = "application/x-www-form-urlencoded";
            //The length of the buffer (postvars) is used as contentlength.
            WebReq.ContentLength = buffer.Length;
            //We open a stream for writing the postvars
            Stream PostData = WebReq.GetRequestStream();
            //Now we write 
            PostData.Write(buffer, 0, buffer.Length);
            // Afterwards, we close. Closing is always important!
            PostData.Close();
            
            //Get the response handle
            //HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
            
            //Let's show some information about the response
            //Console.WriteLine(WebResp.StatusCode);
            //Console.WriteLine(WebResp.Server);

            //Now, we read the response (the string), and output it.
            //Stream Answer = WebResp.GetResponseStream();
            //StreamReader _Answer = new StreamReader(Answer);
            //Console.WriteLine(_Answer.ReadToEnd());
  
        }


Thanks.
Posted
Updated 11-Jun-14 23:15pm
v2
Comments
Nirav Prabtani 12-Jun-14 5:16am    
what is an issue.. :)
Member 10872485 12-Jun-14 5:20am    
this code is in the side of the desktop application, what I'm asking is how I can recover the data from the web service that I have, so what is the code to write or what are the class to use ?

Thanks
Nirav Prabtani 12-Jun-14 5:24am    
you have put URL "http://127.0.0.1/MyWebS.asmx"
first host your webservice in IIS and then call it
BobJanova 12-Jun-14 8:34am    
Isn't it just the commented out part at the bottom?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900