
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
ASP.NET is a free web framework for building great websites and web applications using HTML, CSS, and JavaScript. You can also create Web APIs .
Typology: Lecture notes
1 / 32
This page cannot be seen from the preview
Don't miss anything!
Writing Datasets to XML – Reading Datasets with XML – Web Services : Remote method call
using XML , SOAP – Web Service Description Language, Building and Consuming a Web
Service, Web Application Deployment.
What is SOAP?
SOAP is an XML-based protocol for accessing web services over HTTP. It has some specification which could be used across all applications.
SOAP is known as the Simple Object Access Protocol, but in later times was just shortened to SOAP v1.2. SOAP is a protocol or in other words is a definition of how web services talk to each other or talk to client applications that invoke them.
SOAP was developed as an intermediate language so that applications built on various programming languages could talk easily to each other and avoid the extreme development effort.
SOAP Introduction
In today's world, there is huge number of applications which are built on different programming languages. For example, there could be a web application designed in Java, another in .Net and another in PHP.
Exchanging data between applications is crucial in today's networked world. But data exchange between these heterogeneous applications would be complex. So will be the complexity of the code to accomplish this data exchange.
One of the methods used to combat this complexity is to use XML (Extensible Markup Language) as the intermediate language for exchanging data between applications.
Every programming language can understand the XML markup language. Hence, XML was used as the underlying medium for data exchange.
But there are no standard specifications on use of XML across all programming languages for data exchange. That is where SOAP comes in.
SOAP was designed to work with XML over HTTP and have some sort of specification which could be used across all applications. We will look into further details on the SOAP protocol in the subsequent chapters.
Advantages of SOAP
SOAP is the protocol used for data interchange between applications. Below are some of the reasons as to why SOAP is used.
When developing Web services, you need to have some of language which can be used for web services to talk with client applications. SOAP is the perfect medium which was developed in order to achieve this purpose. This protocol is also recommended by the W3C consortium which is the governing body for all web standards. SOAP is a light-weight protocol that is used for data interchange between applications. Note the keyword ' light .' Since SOAP is based on the XML language, which itself is a light weight data interchange language, hence SOAP as a protocol that also falls in the same category. SOAP is designed to be platform independent and is also designed to be operating system independent. So the SOAP protocol can work any programming language based applications on both Windows and Linux platform. It works on the HTTP protocol – SOAP works on the HTTP protocol, which is the default protocol used by all web applications. Hence, there is no sort of customization which is required to run the web services built on the SOAP protocol to work on the World Wide Web.
SOAP Building blocks
The SOAP specification defines something known as a " SOAP message " which is what is sent to the web service and the client application.
The diagram below shows the various building blocks of a SOAP Message.
Whenever a client application calls a method in the web service, the web service will automatically generate a SOAP message which will have the necessary details of the data which will be sent from the web service to the client application.
As discussed in the previous topic, a simple SOAP Message has the following elements –
The Envelope element The header element and The body element The Fault element (Optional)
Let's look at an example below of a simple SOAP message and see what element actually does.
Now, the above SOAP message will be passed between the web service and the client application.
You can see how useful the above information is to the client application. The SOAP message tells the client application what is the name of the Web service, and also what parameters it expects and also what is the type of each parameter which is taken by the web service.
SOAP Envelope Element
The first bit of the building block is the SOAP Envelope.
The SOAP Envelope is used to encapsulate all of the necessary details of the SOAP messages, which are exchanged between the web service and the client application.
The SOAP envelope element is used to indicate the beginning and end of a SOAP message. This enables the client application which calls the web service to know when the SOAP message ends.
The following points can be noted on the SOAP envelope element.
Every SOAP message needs to have a root Envelope element. It is absolutely mandatory for SOAP message to have an envelope element. Every Envelope element needs to have at least one soap body element. If an Envelope element contains a header element, it must contain no more than one, and it must appear as the first child of the Envelope, before the body element. The envelope changes when SOAP versions change. A v1.1-compliant SOAP processor generates a fault upon receiving a message containing the v1.2 envelope namespace. A v1.2-compliant SOAP processor generates a Version Mismatch fault if it receives a message that does not include the v1.2 envelope namespace.
Below is an example of version 1.2 of the SOAP envelope element.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope"
SOAP-ENV:encodingStyle=" http://www.w3.org/2001/12/soap-encoding">
<soap:Body>
</SOAP-ENV:Envelope>
The Fault message
When a request is made to a SOAP web service, the response returned can be of either 2 forms which are a successful response or an error response. When a success is generated, the response from the server will always be a SOAP message. But if SOAP faults are generated, they are returned as "HTTP 500" errors.
Let's consider the below diagram to see how this communication works. In this example, let's assume the server hosts a web service which provided 2 methods as
GetEmployee - This would get all Employee details SetEmployee – This would set the value of the details like employees dept, salary, etc. accordingly.
In the normal RPC style communication, the client would just call the methods in its request and send the required parameters to the server, and the server would then send the desired response.
The above communication model has the below serious limitations
To overcome all of the limitations cited above, SOAP would then use the below communication model
The WriteXml method writes the current data (the schema and data) of a DataSet object to an XML file. This is an overloaded method. By using this method, you can write data to a file, stream, TextWriter, or XmlWriter.
The following code snippet writes a DataSet contents to a XML file using the WriteXml method:
To Write Dataset contents to XML File using WriteXml method
Create a Windows Forms or WPF application and add a Button control to the Form/Window. Write the following code snippet for the button control click event handler.
The CreateDynamicDataSet method creates a DataSet object in-memory. If you already have data coming from a database, getting filled in a DataSet, you won't need this method. All you need to do is call the WriteXml method of your DataSet and pass the full path of the XML file.
This example creates a DataSet, fills the data for the DataSet, and writes the data to an XML file.
XML is a platform independent language, so the information formatted in XML can be use in any other platforms (Operating Systems). The .Net technology is widely supported XML file format. The .Net Framework provides the Classes for read, write, and other operations in XML formatted files.
Here Dataset is using an XmlReader for read the content of the file. Locate the XML file using XmlReader and pass the XmlReader as argument of Dataset.
Create an XML file in C#
XML is a platform independent language, so the information formatted in XML can be used in any other platforms (Operating Systems). Once we create an XML file in one platform it can be used in other platforms also. In order to creating a new XML file in C#, we are using XmlTextWriter Class. The class takes FileName and Encoding as argument. Also we are here passing formatting details. The following C# source code creating an XML file product.xml and add four rows in the file.
Open and read XML file in C#
XML is a self describing language and it gives the data as well as the rules to extract what data it contains. Reading an XML file means that we are reading the information embedded in XML tags in an XML file.
C# XML Parser
We create an XML file and named it as products.xml. The following C# program read that file and extract the contents inside the XML tag. We can read an XML file in several ways depends on our requirement. This program read the content in Node wise. Here we are using XmlDataDocument Class to read the XML file. In this program it search the Node and its child Nodes and extract the data in child nodes.
using System; using System.Data; using System.Windows.Forms; using System.Xml; using System.IO; namespace WindowsApplication { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode ; int i = 0; string str = null; FileStream fs = new FileStream("product.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("Product"); for (i = 0; i <= xmlnode.Count - 1; i++) { xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + " " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + " " + xmlnode[i].ChildNodes.Item(2).InnerText.Trim(); MessageBox.Show (str); } } } }
Reading Xml with XmlReader
XmlReader opens and parses XML files. It is a faster and less memory consuming alternative. It lets you run through the XML string one element at a time, while allowing you to look at the value, and then moves on to the next XML element. It provides a lower-level abstraction over the XML file structure.
XmlReader xReader = XmlReader.Create(new StringReader(xmlNode)); while (xReader.Read()) { switch (xReader.NodeType)
Example of Reading Dataset with XML
using System; using System.Data; using System.Xml; using System.IO; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("d:\product.xml"); XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/Table/Product"); string proID = "", proName = "", price=""; foreach (XmlNode node in nodeList) { proID = node.SelectSingleNode("Product_id").InnerText; proName = node.SelectSingleNode("Product_name").InnerText; price = node.SelectSingleNode("Product_price").InnerText; MessageBox.Show(proID + " " + proName + " " + price); } } } }
The XML-RPC is a XML based protocol. It is a simple protocol used to exchange information between computer systems over a network. It is a remote procedure call and it uses XML to encode the calls. The XML-RPC uses HTTP for transport. It allows complex data structures to be transmitted and processed. The XML-RPC protocol was created by Dave winer in 1998.
XML-RPC Working
The XML-RPC will help you if you want to integrate multiple computing environments without need to share the complex data structures directly. The communication between computers over a network can be established fast and easily with the help of XML-RPC. It can be used in association with Perl, Java, Python, C, C++, PHP and many other programming languages. ie., it will allow java to communicate with Perl, Python, ASP, and so on. Let’s see how does the XML-RPC
work. An XML-RPC message is actually an HTTP-POST request. There are requests and responses. The request’s body will be in XML. A procedure executes on the server. It will return a value and this value also will be in the XML format. The procedure parameters can be numbers, strings, scalars, dates, … Let’s have a look on the formats of XML-RPC requests and responses in this documentation.
XML-RPC supported Data Types
They are listed below. These data types are explained below.
These are the types of data that are supported by XML-RPC. Each data type is explained below with examples.
int : The int data type represents an integer. This is an integer which is of the following format. It is a signed integer and it is 32-bit in size.
double : It is a floating-point number. It is of double precision. In some implementations, the accuracy may vary for this data type.
boolean : It represents the boolean operations the ‘true’ and ‘false’.
dateTime.iso8601 : As the name indicates, this is the data type used for a date and time. For the XML-RPC, it is quite useless because the XML-RPC forbids the use of time zones.
string : This data type represents an ASCII string. It can also have NULL bytes.
base64 : All the raw binary data of any length will be encoded using this data type.
array : The array data type is familiar to all developers. Here, it is the one-dimensional array structure.
struct : In XML-RPC, there can have many key-value pairs. These pairs will be stored using the struct data type.
Tag Type Example
If there is no type indicated, then it will be string by default.
XML-RPC Response
The following is a sample XML-RPC response. HTTP/1.1 200 OK Connection: close Content-Length: 162 Content-Type: text/xml Date: Fri, 21 Aug 1994 17:45:06 GMT Server: Example Frontier/5.1.2-WinNT
The first line is HTTP/1.1 200 OK. It will be 200 OK unless there is a lower level. As in the request, the Content-length must be specified correctly. The next line indicates Content-Type is text/xml. The body of the response is a single XML structure, a
WSDL stands for Web Services Description Language. It is the standard format for describing a web service. WSDL was developed jointly by Microsoft and IBM.
Features of WSDL
WSDL is an XML-based protocol for information exchange in decentralized and distributed environments.
WSDL definitions describe how to access a web service and what operations it will perform.
WSDL is a language for describing how to interface with XML-based services.
WSDL is an integral part of Universal Description, Discovery, and Integration (UDDI), an XML-based worldwide business registry.
WSDL is the language that UDDI uses.
WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'.
WSDL Usage
WSDL is often used in combination with SOAP and XML Schema to provide web services over the Internet. A client program connecting to a web service can read the WSDL to determine what functions are available on the server. Any special datatypes used are embedded in the WSDL file in the form of XML Schema. The client can then use SOAP to actually call one of the functions listed in the WSDL.
History of WSDL
WSDL 1.1 was submitted as a W3C Note by Ariba, IBM, and Microsoft for describing services for the W3C XML Activity on XML Protocols in March 2001.
WSDL 1.1 has not been endorsed by the World Wide Web Consortium (W3C), however it has just released a draft for version 2.0 that will be a recommendation (an official standard), and thus endorsed by the W3C.
WSDL breaks down web services into three specific, identifiable elements that can be combined or reused once defined.
The three major elements of WSDL that can be defined separately are −
Types Operations Binding
A WSDL document can also contain other elements, like extension elements and a service element that makes it possible to group together the definitions of several web services in one single WSDL document.
A web service is a web based functionality that we can use in different platforms using protocols. It is language independent, we can write web services in any language and access the same using any other language, the web service will pass the data using XML format. Web services communicates mainly by using http protocol.
Creating Web Service
In this example I am going to create a simple web service with the following details,
Create ASP.Net web service with Get All employee details method. Web service method will get employee details from Database. Create web application to access and bind the response details to grid.
Steps to create Web Service