Web Services Part I – SOAP

Hi All! , hope you are doing well. Let us today discuss Services, History, importance and usage and Web Service Security. We shall also discuss various kinds of Web Service and their applicability.

What is a Web Service?

Web service is a system or service, to interact with another system. In a Web technology HTTP is also a web service, but this is human to machine interfacing service.  Sometime, we need system to system communication, therefore Web Services were introduced. As for as definition is concerned, as per W3C glossary

A web service is a software system designed to support inter-operable machine-to-machine interaction over a .

Similarly as per Wikipedia:

A web service is a service offered by an electronic device to another electronic device, communicating with each other via the World Wide Web.  In practice, the web service typically provides an object-oriented web-based interface to a database server, utilized for example by another web server, or by a mobile application, that provides a user interface to the end user.

web-service photo

Type of Web Services

There are mainly two kinds of Web Services, and .

Simple Object Access Protocol (SOAP)

SOAP (Simple Object Access Protocol) is protocol specifications to exchange structured information on the World Wide Web using XML messaging format, relies on application layer protocols like HTTP and SMTP (Simple Mail Transfer Protocol). SOAP has three basic characteristics Extensibility, Neutrality (compatible to protocols used) and independence (can be used with any programming model).  SOAP has three basic components:

  1. An Envelope ( defines message structure and processing instructions)
  2. Set of Encoding Rules ( to accommodate application specific data types)
  3. A convention of procedural calls and responses.

SOAP Architecture

SOAP architecture has following layers:

  • Message Format
  • Message Exchange Pattern
  • Transport protocol bindings
  • Message processing model
  • Protocol extensibility

SOAP History

SOAP was successor of XML-RPC protocol and few older failed technologies like Distributed Component Object Model (DCOM) and Common Object Request Broker Architecture (CORBA) SOAP was designed as object access protocol in 1998 by Dave Winer and few more engineers for Microsoft, but due to some reasons, it did not reach to W3C till 2000. Finally in 2003, version 1.2 specification was added as W3C standard recommendation.

Sample of SOAP Web Service (in C#)


using System.Xml;
using System.Net;
using System.IO;

public static void CallWebService()
{
var _url = "http://xxxxxxxxx/Service1.asmx";
var _action = "http://xxxxxxxx/Service1.asmx?op=HelloWorld";

XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
HttpWebRequest webRequest = CreateWebRequest(_url, _action);
InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

// begin async call to web request.
IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

// suspend this thread until call is complete. You might want to
// do something usefull here like update your UI.
asyncResult.AsyncWaitHandle.WaitOne();

// get the response from the completed web request.
string soapResult;
using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
{
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}
.Write(soapResult);
}
}

private static HttpWebRequest CreateWebRequest(string url, string action)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Headers.Add("SOAPAction", action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}

private static XmlDocument CreateSoapEnvelope()
{
XmlDocument soapEnvelop = new XmlDocument();
soapEnvelop.LoadXml(@"1232");
return soapEnvelop;
}

private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
}

Pros and Cons of SOAP

PROS

  • Highly extendable
  • Language, platform, and transport agnostic.
  • Designed to handle distributed computing environments
  • oldest standard for web services, and hence has better support from other standards (WSDL, WS-*) and tooling from vendors.
  • Built-in error handling (faults)

CONS

  • Complex
  • Conceptually more difficult, more “heavy-weight” than REST.
  • More verbose.
  • Harder to develop, requires .

In this article we discussed about SOAP Web Services, Is this is the only method available?, If it is so complex then what are the alternatives? There is one simple alternative to SOAP web services, that's called RESTFUL Web Services, we shall discuss about REST services in next post. Till then goodbye.

Jitendra Chaudhary
Follow me
Latest posts by Jitendra Chaudhary (see all)
I hope you would find above article informative and  interesting. In case you need any further information, please feel free to comment , I shall try to reply the comment at the earliest. If you like this article, please like my Facebook page and advise/suggest me for more topics of your interest. Happy Coding!

Related posts