C# simple soap example call

Can you provide a simple c# example soap call
Brant SnowAsked:
Who is Participating?
Miguel OzConnect With a Mentor Software EngineerCommented:
A sample tutorial is shown here
The tutorial is for VS2010 but these are the same steps for Vs2013 as well. Steps 4 to 7 add Web Reference to your target SOAP web service.
Praveen Kumar BonalaConnect With a Mentor Programmer AnalystCommented:
//snippet of c# calling webservice using soap 1.2
string xmlstr = @"<?xml version=""1.0"" encoding=""utf-8""?> <soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope"">
<GetPlannedWorkSummary xmlns=""http://tempuri.org/"">
//call web service funciton
//sample function
public static void SampleWebServiceCall(string requestXML, string url) {
string response = string.Empty;
byte[] requestBuffer = null;
HttpWebRequest webRequest = null;
HttpWebResponse webResponse = null;
Stream postStream = null;
Stream responseStream = null;
StreamReader responseReader = null;
DateTime startTime = new DateTime();
DateTime endTime = new DateTime();
requestBuffer = Encoding.ASCII.GetBytes(requestXML);
webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "text/xml";
webRequest.ContentLength = requestBuffer.Length;
postStream = webRequest.GetRequestStream();
postStream.Write(requestBuffer, 0, requestBuffer.Length); postStream.Close();
webResponse = (HttpWebResponse)webRequest.GetResponse(); responseStream = webResponse.GetResponseStream();
responseReader = new StreamReader(responseStream);
response = responseReader.ReadToEnd();
catch (Exception ex)
if (postStream != null)
if (webResponse != null)
echobridgeConnect With a Mentor Senior Software EngineerCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.