SolvedPrivate

C# simple soap example call

Posted on 2015-01-28
3
27 Views
Last Modified: 2016-02-16
Can you provide a simple c# example soap call
0
Comment
Question by:Brant Snow
3 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 167 total points
ID: 40576543
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.
0
 
LVL 4

Assisted Solution

by:Praveen Kumar Bonala
Praveen Kumar Bonala earned 167 total points
ID: 40576553
//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"">
 
<soap12:Body>
 
<GetPlannedWorkSummary xmlns=""http://tempuri.org/"">
 
<timestamp>2010-01-10</timestamp>
 
</GetPlannedWorkSummary>
 
</soap12:Body>
 
</soap12:Envelope>";
 
//call web service funciton
 
SampleWebServiceCall(xmlstr,url);
 
//sample function
public static void SampleWebServiceCall(string requestXML, string url) {
//declarations
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();
 
try
{
 
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)
{
 
}
finally
{
if (postStream != null)
{
postStream.Dispose();
}
if (webResponse != null)
{
webResponse.Close();
}
}
0
 
LVL 1

Assisted Solution

by:echobridge
echobridge earned 166 total points
ID: 40577554
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question