Saturday, 3 October 2015

How to make request to webservice with soap message - asp.net /C#

Leave a Comment
If you have webservice and want to call the web service from your c# code, you can try to use this method example.

Code Behind

         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(<web service address>);  
         request.Headers.Add("SOAPAction", "http://tempuri.org/" + <web service method>);  
         request.ContentType = "text/xml;charset=\"utf-8\"";  
         request.KeepAlive = false;  
         request.Timeout = 300000; // - in millisecond. (5 minit)  
         request.Method = "POST";  
         request.Credentials = CredentialCache.DefaultCredentials;  
         byte[] byteArray = Encoding.ASCII.GetBytes(<data you want to send to webservice>);  
         request.ContentLength = byteArray.Length;  
         Stream s = request.GetRequestStream();  
         s.Write(byteArray, 0, byteArray.Length);  
         s.Dispose();  
         s.Close();  
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();  
         Encoding enc = System.Text.Encoding.GetEncoding(1252);  
         StreamReader resStream = new StreamReader(response.GetResponseStream());  
         result = resStream.ReadToEnd(); // read webservice response
         dataToSend = "";  
         resStream.Dispose();  
         resStream.Close();  
         response.Close();  
         return result;  


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.