SolvedPrivate

C# simple soap example call

Posted on 2015-01-28
3
35 Views
Last Modified: 2016-02-16
Can you provide a simple c# example soap call
0
Comment
Question by:Brant Snow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 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