Continuing on my last article, which showed a simple SOAP request in PHP, this article will do the same using C#. The IDE I am using is Visual Studio Community Edition. The core technologies here are C#, and SOAP. I presume a familiarity with C#. SOAP, or Simple Object Access Protocol, is a Web Service which utilizes XML as it’s format and, in our examples, the data is transmitted via HTTP. As such, I presume a basic understanding of HTTP, and general Markup as you might find in HTML or XML.
The WSDL file
Our query against the SOAP web service will be dictated by the WSDL file provided for the web service in question. The WSDL file provides a contract, or user manual, listing the available functions we can call, along with information such as input data we can provide, and data we can expect to be returned.
I will be using a publicly available SOAP Web Service, and as such, it’s WSDL file; the file can be viewed in your browser by following the link, or downloaded and opened for analysis using Notepad, or Notepad++ in a Microsoft Windows environment:
http://footballpool.dataaccess.eu/data/info.wso?wsdl
Reviewing the WSDL file, we can see a number of functions; here is a simple one with one input variable:
<xs:element name=”AllMidFields“></xs:element>
<service name=”Info“></service>
using ConsoleApplication1.ServiceReference1;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string country = “Australia”;
string endpointConfigurationName = “InfoSoap12”;
InfoSoapTypeClient iSTC = new InfoSoapTypeClient(endpointConfigurationName);
ArrayOfString aOS = iSTC.AllMidFields(country);
if (!aOS.Equals(null))
{
System.Console.WriteLine(“There are {0} returned values.”, aOS.Count);foreach (string element in aOS)
{
System.Console.WriteLine(element);
}
} else
{
System.Console.WriteLine(“{0}”, “No data returned.”);
}
System.Threading.Thread.Sleep(100000);
}
}
}
And these are the results when run:
- There are 11 returned values.
- Ben Halloran
- Dario Vidosic
- James Holland
- James Troisi
- Mark Bresciano
- Mark Milligan
- Massimo Luongo
- Matt McKay
- Mile Jedinak
- Oliver Bozanic
- Tommy Oar