• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 53
  • Last Modified:

C# simple soap example call

Can you provide a simple c# example soap call
Brant Snow
Brant Snow
3 Solutions
Miguel OzSoftware 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 BonalaCommented:
//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)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now