Anda di halaman 1dari 63

www.Vidyarthiplus.

com

MADHA ENGINEERING COLLEGE


(A CHRISTIAN MINORITY INSTITUTION, KUNDRATHUR, CHENNAI- 600069)

Department of MCA
XML AND WEB SERVICES LAB (MC7512)

Name : _____________________________

Reg. No : _____________________________

Semester : V

Academic Year : 2016-2017

www.Vidyarthiplus.com
www.Vidyarthiplus.com

MADHA ENGINEERING COLLEGE


(A CHRISTIAN MINORITY INSTITUTION, KUNDRATHUR, CHENNAI- 600069)

REGISTRATION NO:

BONAFIDE CERTIFICATE

This is to certify that it is the bonafide record of the practical work done by
Mr/Ms......................................................... of MCA (Master Of Computer
Applications) in the .............................................................. Laboratory during the
academic year 2016-2017.

--------------------------- -----------------------------------
Staff-In charge Head of the Department

Submitted for the Anna university practical examination held on ____________

---------------------------- -----------------------------
Internal Examiner External Examiner

www.Vidyarthiplus.com
www.Vidyarthiplus.com

INDEX
Exp Page
Date Name of the Experiment Signature
No No
1 XML Document Creation

Importing and Exporting XML


2
Document in Database

3 XSL Transformation

4(a) Internal DTD Creation

4(b) External DTD Creation

5 XML Schema Creation

Parsing XML Document Using


6
DOM/SAX Parser

Web Service Creation Using JAX-WS


7(a)
For Currency Conversion

Web Service Creation Using JAX-WS


7(b)
For Temperature Conversion

8 Web Service Creation Using JAX-RS

Web Service Creation Using .NET For


9(a)
Currency Conversion

Web Service Creation Using .NET For


9(b)
Temperature Conversion

10(a) JAXB Marshaling

10(b) JAXB UnMarshaling

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:1 XML DOCUMENT CREATION


Date:

Aim:
To create a simple XML document to display the address book.

Procedure:
Step-1: Create the xml document using notepad.
Step-2: Create the addressbook as a root tag.
Step-3: Followed by create a three employees address in detail using different tag.
Step-4: Save the file as Employee.xml.
Step-5: Finally execute the program in Internet Explorer to view the output.

Source Code:
Filename: Employee.xml

<?xml version = "1.0" encoding="UTF-8" standalone="yes" ?>


<addressbook>
<emp1>
<name>Karthick</name>
<doorno>No-2/57</doorno>
<street>Vinayakam St</street>
<area>Teynampet</area>
<city>Chennai-600020</city>
<state>Tamil Nadu</state>
<country>India</country>
<phoneno>909583625</phoneno>
</emp1>
<emp2>
<name>Murali</name>
<doorno>No-25/7</doorno>
<street>ParthasarathyKoil Street</street>
<area>Triplecane</area>
<city>Chennai-600005</city>
<state>Tamil Nadu</state>
<country>India</country>
<phoneno>9962589632</phoneno>
</emp2>
<emp3>
<name>Jagagish</name>
<doorno>No-25</doorno>
<street>Palani Street,</street>
<area>Manali</area>
<city>Chennai-600055</city>
<state>Tamil Nadu</state>
<country>India</country>
<phoneno>9003862541</phoneno>
</emp3>
</addressbook>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

Result:
Thus, the simple xml document creation has been executed successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:2 IMPORTING AND EXPORTING XML DOCUMENT


Date: IN DATABASE

Aim:
To create a xml document and database for importing and exporting xml document into
database.

Procedure:
Step-1: Start the process.
Step-2: Create the xml document using notepad and write the following code:

Source Code:
Filename: Hello.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<student-data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<Name>Karthi</Name>
<Age>19</Age>
<Major>Chemistry</Major>
<GPA>8.8</GPA>
</record>
<record>
<Name>Raj</Name>
<Age>23</Age>
<Major>Maths</Major>
<GPA>5.5</GPA>
</record>
</student-data>

Step-3: Save the xml document as .xml extension.


Step-4: Click start->All programs->Microsoft office->Microsoft Excel 2007.
Step-5: Enable the Developer Tab:

If the Developer tab is not available, you need to enable it in the options. Click on File, and then go
all the way down to Options. Click on the Customize Ribbon section, and in the column on the
right, there should be a list of tabs called Main Tabs that you can check or uncheck.
Find where it says Developer, and make sure the box is checked. Then click OK. The Developer
tab should now be up top, to the right of the View tab.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-6: To import the xml document click->Developer tab ->Sources.


Step-7: Add an XML Map:
In the XML Source task pane, click the XML Maps option at the very bottom right. A window will
pop up.

Click Add to add a browse the location of xml document and click ok.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-8: Drag and drop XML elements into the spreadsheet and import the XML file into Excel. Add
the new record into the database.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-9: Once finished converting each column into an XML element, return to the Developer tab,
find the XML section again, and click Export. Save your XML file, and then open it in Notepad to
see the results:

Step-10: Stop the process.

Result:
Thus, the program to importing and exporting XML into Excel-database has been executed
successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:3 XSL TRANSFORMATION


Date:

Aim:
To create a simple XSLT transformation from XSL to XML.

Procedure:
Step-1: Create a XSLT document using notepad.
Step-2: Using XSLT document, we can create a style sheet like Font Style, Font Size, bgcolor,..etc.
and write the following code:

Source Code:

Filename:cdcatalog.xsl

<?xml version="1.0" encoding="UTF-8" ?>


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<trbgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Step-3: Save the document as Filename.xsl.


Step-4: Then create a XML document.
Step-5: Create a Link with the XSLT document using href tag=Filename.xsl and write the
following code:

Source Code:
Filename: Simpxsl.xml

<?xml version="1.0" encoding="UTF-8" ?>


<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Still got the blues</title>
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</cd>
<cd>
<title>Sylvias Mother</title>
<artist>Dr.Hook</artist>
<country>UK</country>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

<company>CBS</company>
<price>8.10</price>
<year>1973</year>
</cd>
<cd>
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.50</price>
<year>1990</year>
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
<cd>
<title>When a man loves a woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Black angel</title>
<artist>Savage Rose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.90</price>
<year>1995</year>
</cd>
<cd>
<title>1999 Grammy Nominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.20</price>
<year>1999</year>
</cd>
<cd>
<title>For the good times</title>
<artist>Kenny Rogers</artist>
<country>UK</country>
<company>Mucik Master</company>
<price>8.70</price>
<year>1995</year>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

</cd>
<cd>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Tupelo Honey</title>
<artist>Van Morrison</artist>
<country>UK</country>
<company>Polydor</company>
<price>8.20</price>
<year>1971</year>
</cd>
<cd>
<title>Soulsville</title>
<artist>JornHoel</artist>
<country>Norway</country>
<company>WEA</company>
<price>7.90</price>
<year>1996</year>
</cd>
<cd>
<title>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>
<title>Stop</title>
<artist>Sam Brown</artist>
<country>UK</country>
<company>A and M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>Bridge of Spies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Private Dancer</title>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

<artist>Tina Turner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
<year>1983</year>
</cd>
<cd>
<title>Midtomnatten</title>
<artist>Kim Larsen</artist>
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>
<year>1991</year>
</cd>
<cd>
<title>The dock of the bay</title>
<artist>Otis Redding</artist>
<country>USA</country>
<company>Atlantic</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Picture book</title>
<artist>Simply Red</artist>
<country>EU</country>
<company>Elektra</company>
<price>7.20</price>
<year>1985</year>
</cd>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

<price>8.20</price>
<year>1987</year>
</cd>
</catalog>

Step-6: Save the document as Simpxsl.xml.


Step-7: Then execute the xml file and view the output:

Result:
Thus the program to convert the simple XSLT transformation from XSL to XML has been
executed successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:4(i) INTERNAL DTD CREATION


Date:

Aim:
To create a XML program for Internal DTD(Document Type Definition) creation.

Procedure:
Step-1: Open the notepad.
Step-2: Create a DTD document for book details.
Step-3:Save the document as Filename.xml.
Step-4:Type a XML Parser using HTML coding.
Step-5:Save the document as Filename.html.
Step-6:Execute the program in Internet Explorer.

Source Code:

File name:Sche.xml

<?xml version="1.0" ?>


<!DOCTYPE books [
<!ELEMENT books (book)*>
<!ELEMENT book (title?,isbn+,(zipcode|author),publish*)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT zipcode (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT publish (#PCDATA)>
<!ATTLIST zipcode zname CDATA "232232323">
<!ATTLIST publish year CDATA #FIXED "1995">
<!ATTLIST title name CDATA #IMPLIED>
<!ATTLIST isbn number CDATA #REQUIRED>
]>
<books>
<book>
<title name="C"></title>
<isbn number="2309"></isbn>
<zipcode zname="23244345345"></zipcode>
<publish year="1998"></publish>
</book>
<book>
<title name="C++"></title>
<isbn number="2310"></isbn>
<zipcode zname="45814845585"></zipcode>
<publish year="1995"></publish>
</book>
<book>
<title name="JAVA"></title>
<isbn number="2311"></isbn>
<zipcode zname="553378845585"></zipcode>
<publish year="1995"></publish>
</book>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

<book>
<title name="PUZZLES"></title>
<isbn number="2313"></isbn>
<zipcode zname="456644445"></zipcode>
<publish year="1995"></publish>
</book>
<book>
<title name="XML"></title>
<isbn number="2312"></isbn>
<zipcode zname="412684895585"></zipcode>
<publish year="1995"></publish>
</book>
</books>

Filename:Par.html

<html>
<body>
<h3>This demonstrates a parser error:</h3>
<script type="text/javascript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.validateOnParse="true";
xmlDoc.load("Sche.xml");
document.write("<br/>Error Code:");
document.write(xmlDoc.parseError.errorCode);
document.write("<br/>Error Reason:");
document.write(xmlDoc.parseError.reason);
document.write("<br/>Error Line:");
document.write(xmlDoc.parseError.line);
</script>
</body>
</html>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

Result:
Thus, the XML program for creating Internal DTD has been executed successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:4(ii) EXTERNAL DTD CREATION


Date:

Aim:
To create a XML program for External DTD(Document Type Definition) creation.

Procedure:
Step-1: Open the notepad.
Step-2: Create a DTD document for book details.
Step-3: Save the document as Filename.dtd.
Step-4: Create a XML document for book details.
Step-5: Save the document as Filename.xml.
Step-6: Type a XML Parser using HTML coding.
Step-7: Save the document as Filename.html.
Step-8: Execute the program in Internet Explorer.

Source Code:
Filename:not.dtd

<!ELEMENT books (book)*>


<!ELEMENT book (title?,isbn+,(zipcode|author),publish*)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT zipcode (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT publish (#PCDATA)>
<!ATTLIST zipcode zname CDATA "232232323">
<!ATTLIST publish year CDATA #FIXED "1995">
<!ATTLIST title name CDATA #IMPLIED>
<!ATTLIST isbn number CDATA #REQUIRED>

Filename: Sc.xml

<?xml version="1.0" ?>


<!DOCTYPE books SYSTEM "not.dtd">
<books>
<book>
<title name="C"></title>
<isbn number="2309"></isbn>
<zipcode zname="23244345345"></zipcode>
<publish year="1995"></publish>
</book>
<book>
<title name="C++"></title>
<isbn number="2310"></isbn>
<zipcode zname="23244345345"></zipcode>
<publish year="1995"></publish>
</book>
</books>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Filename:Pars.html

<html>
<body>
<h3>This demonstrates a parser error:</h3>
<script type="text/javascript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.validateOnParse="true";
xmlDoc.load("Sc.xml");
document.write("<br/>Error Code:");
document.write(xmlDoc.parseError.errorCode);
document.write("<br/>Error Reason:");
document.write(xmlDoc.parseError.reason);
document.write("<br/>Error Line:");
document.write(xmlDoc.parseError.line);
</script>
</body>
</html>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

Result:
Thus, the XML program for creating External DTD has been executed successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:5 XML SCHEMA CREATION


Date:

Aim:
To create a program for XML Schema creation and display element and attributes.

Procedure:
Step-1: Open the XMLwriter.
Step-2: Click File->New->XML Document and name the Filename.
Step-3:Type the following program:

Source Code:

Filename:Sche.xml

<?xml version="1.0" encoding="UTF-8" ?>


<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="sche.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Karthick</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>5</quantity>
<price>9.90</price>
</item>
</shiporder>

Step-4: Click File->New->XML Schema File and name the Filename.


Step-5: Type the following code:

Source Code:
Filename:sche.xsd

<?xml version="1.0" encoding="UTF-8" ?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>

www.Vidyarthiplus.com
www.Vidyarthiplus.com

<xs:element name="orderperson" type="xs:string" />


<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="address" type="xs:string" />
<xs:element name="city" type="xs:string" />
<xs:element name="country" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="note" type="xs:string" minOccurs="0" />
<xs:element name="quantity" type="xs:positiveInteger" />
<xs:element name="price" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>

Step-6: Finally validate the xml file by pressing the F7 key.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

Result:
Thus, the program for XML Schema creation and display element and attributes has been
executed successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:6 PARSING XML DOCUMENT USING DOM/SAX


Date: PARSER

Aim:
To create a parsing XML document using DOM(Document Object Model) parser.

Procedure:
Step-1: Open the notepad.
Step-2: Create a xml document for book collection.
Step-3: Save the document as Filename.xml.
Step-4: Type the following program:

Source Code:

Filename:Bookcollection.xml

<bookdb>
<book>
<name>Java Complete Reference</name>
<author>lan</author>
<year>2001</year>
<publication>Tata McDraw Hill</publication>
</book>
<book>
<name>C# Complete Reference</name>
<author>balagurusamy</author>
<year>2006</year>
<publication>Persion Addition</publication>
</book>
<book>
<name>Complete Reference</name>
<author>Kanithkar</author>
<year>2005</year>
<publication>Tata McDraw Hill</publication>
</book>
</bookdb>

Step-5:Create a html program and save the file as Filename.html.


Step-6:Type the following program:

Source Code:
Filename: Bookdetailsdom.html

<html>
<head>
<script language="javascript">
var root;
var xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.load("Bookcollection.xml");

www.Vidyarthiplus.com
www.Vidyarthiplus.com

function start()
{
if(xmldoc.readyState=="4")
loading();
else
alert("could not load");
}
function loading()
{
var i;
root=xmldoc.documentElement;
var count;
count=root.childNodes.length;
for(i=0;i<count;i++)
{
document.write(root.childNodes.item(i).text+"<br>");
}
}
</script>
</head>
<body onLoad="start()">
</body>
</html>

Step-7: Finally, execute the html program in Internet Explorer.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

Result:
Thus, the parsing XML document using DOM(Document Object Model) parser has been
executed successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:7(i) WEB SERVICE CREATION USING JAX-WS FOR


Date: CURRENCY CONVERSION

Aim:
To create a Web Service program using JAX-WS for currency conversion.

Procedure:
Step-1: Open the NetBeans IDE.
Step-2: Choose File->New Project. Select Web Application from the Java Web category from the
Java EE category.
Step-3: Name the project CurWSApplication. Select a location for the project. Click Next.
Step-4: Select the GlassFish Server and Java EE version and click Finish.
Step-5: Right-click the CurWSApplication node and choose New->Web Service.
Step-6: Name the web service CurWS and type org.me.calculator in Package and Click Finish.

Step-7: Click the Design View in the editor.


Step-8: Click the Add Operation in the Design View dialog box. The Add Operation dialog box
opens.
Step-9: In the upper part of the Add Operation dialog box, type RupeesToDollar in Name and type
double in Return Type drop-down list.
Step-10: In the lower part of the Add Operation dialog box, click Add and create a parameter of type
double named Rupees.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-11: Click OK.


Step-12: Click the Add Operation in the Design View dialog box. The Add Operation dialog box
opens.
Step-13: In the upper part of the Add Operation dialog box, type RupeesToEuro in Name and type
double in Return Type drop-down list.
Step-14: In the lower part of the Add Operation dialog box, click Add and create a parameter of type
double named Rupees.

Step-15: Click OK.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-16: Click the Add Operation in the Design View dialog box. The Add Operation dialog box
opens.
Step-17: In the upper part of the Add Operation dialog box, type RupeesToPounds in Name and
type double in Return Type drop-down list.
Step-18: In the lower part of the Add Operation dialog box, click Add and create a parameter of type
double named Rupees.

Step-19: Click OK.


Step-20: Click the Add Operation in the Design View dialog box. The Add Operation dialog box
opens.
Step-21: In the upper part of the Add Operation dialog box, type RupeesToReal in Name and type
double in Return Type drop-down list.
Step-22: In the lower part of the Add Operation dialog box, click Add and create a parameter of type
double named Rupees.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-23: Click OK.


Step-24: Click the Add Operation in the Design View dialog box. The Add Operation dialog box
opens.
Step-25: In the upper part of the Add Operation dialog box, type RupeesToRiggit in Name and type
double in Return Type drop-down list.
Step-26: In the lower part of the Add Operation dialog box, click Add and create a parameter of type
double named Rupees.

Step-27: Click OK.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-28: Edit the following code in the CurWS class of CurWS.java file:

Source Code:

@WebService(serviceName = "CurWS")
public class CurWS
{

@WebMethod(operationName = "RupeesToDollar")
public double RupeesToDollar(@WebParam(name = "Rupees") double Rupees)
{
return (Rupees/46.5);
}

@WebMethod(operationName = "RupeesToEuro")
public double RupeesToEuro(@WebParam(name = "Rupees") double Rupees)
{
return (Rupees/68.64);
}

@WebMethod(operationName = "RupeesToPounds")
public double RupeesToPounds(@WebParam(name = "Rupees") double Rupees)
{
return (Rupees/73.55);
}

@WebMethod(operationName = "RupeesToReal")
public double RupeesToReal(@WebParam(name = "Rupees") double Rupees)
{
return (Rupees/26.7);
}

@WebMethod(operationName = "RupeesToRiggit")
public double RupeesToRiggit(@WebParam(name = "Rupees") double Rupees)
{
return (Rupees/13.67);
}
}

Step-29: Deploy the CurWSApplication.


Step-30: Execute the Web Service by Right-click the Test Web Service in the CurWS Web Service
folder.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Result:
Thus, the Web-Service creation using JAX-WS for currency conversion has been executed
successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:7(ii) WEB SERVICE CREATION USING JAX-WS FOR


Date: TEMPERATURE CONVERSION

Aim:
To create a Web Service program using JAX-WS for temperature conversion.

Procedure:
Step-1:Open the NetBeans IDE.
Step-2:Choose File->New Project. Select Web Application from the Java Web category from the
Java EE category.
Step-3:Name the project TempWSApplication. Select a location for the project. Click Next.
Step-4:Select the GlassFish Server and Java EE version and click Finish.
Step-5:Right-click the TempWSApplication node and choose New->Web Service.
Step-6: Name the web service TempWS and type org.me.calculator in Package and Click Finish.

Step-7: Click the Design View in the editor.


Step-8: Click the Add Operation in the Design View dialog box. The Add Operation dialog box
opens.
Step-9: In the upper part of the Add Operation dialog box, type FarenheitToCelcius in Name and
type double in Return Type drop-down list.
Step-10: In the lower part of the Add Operation dialog box, click Add and create a parameter of type
double named Farenheit.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-11: Click OK.


Step-12: Click the Add Operation in the Design View dialog box. The Add Operation dialog box
opens.
Step-13: In the upper part of the Add Operation dialog box, type CeltoFeh in Name and type double
in Return Type drop-down list.
Step-14: In the lower part of the Add Operation dialog box, click Add and create a parameter of type
double named Ferenheit.

Step-15: Click OK.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-16: Edit the following code in the TempWS class of TempWS.java file:

Source Code:
@WebService(serviceName = "TempWS")
public class TempWS
{

@WebMethod(operationName = "FarenheitToCelcius")
public double FarenheitToCelcius(@WebParam(name = "Farenheit") double Farenheit)
{
return (((Farenheit-32)/9)*5);
}

@WebMethod(operationName = "CelciusToFarenheit")
public double CelciusToFarenheit(@WebParam(name = "Celcius") double Celcius)
{
return (((Celcius*9)/5)+32);
}
}

Step-17: Deploy the TempWSApplication.


Step-18:Execute the Web Service by Right-click the Test Web Service in the TempWS Web Service
folder.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Result:
Thus, the Web-Service creation using JAX-WS for temperature conversion has been
executed successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:8 WEB SERVICE CREATION USING JAX-RS


Date:

Aim:
To create a Web Service program using JAX-RS.

Procedure:
Step-1: Start the process.
Step-2: Select File-> New project -> Java web specify the name.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-3: Right Project->New->RESTFUL web service from pattern.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-4: Write the coding in the GenericResource.java

Source Code:

Filename: GenericResource.java

package main;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;

@Path("generic")
public class GenericResource
{
@Context
private UriInfo context;
public GenericResource()
{}
@GET
@Produces("text/html")
public String getHtml()
{
//TODO return proper representation object
return "<html><body>Welcome to XML Lab</body></html>";
}
@PUT
@Consumes("text/html")
public void putHtml(String content)
{
}
}

Step- 5: Run the program & display the information.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Step-6: Stop the process.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

Result:
Thus, the Web-Service creation using JAX-RS has been executed successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:9(i) WEB SERVICE CREATION USING .NET FOR


Date: CURRENCY CONVERSION

Aim:
To create a Web Service program using .NET for currency conversion.

Procedure:
Step-1: Start->All programs->Microsoft Visual Studio 2010.
Step-2: Select New Project->Visual Basic->WCF Service Application->Filename.
Step-3: A Solution Explorer Window will be displaying on the screen.
Step-4: Right click on the file name and select Add->New Item->Web Service, and then click Add.
Step-5:Within the Web Method type the program for currency conversion.
Step-6: Execute the Web Service program.

Source Code:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function RupeesToDollar(ByVal Rupee As String) As String
Dim rup
rup = Trim(Rupee)
If rup = "" Or IsNumeric(rup) = False Then
Return "Error"
Else
Return (Rupee/46.5)
End If
End Function

<WebMethod()> _
Public Function RupeesToPounds(ByVal Rupee As String) As String
Dim rup
rup = Trim(Rupee)
If rup = "" Or IsNumeric(rup) = False Then
Return "Error"
Else
Return (Rupee / 73.55)
End If
End Function

www.Vidyarthiplus.com
www.Vidyarthiplus.com

<WebMethod()> _
Public Function RupeesToEuro(ByVal Rupee As String) As String
Dim rup
rup = Trim(Rupee)
If rup = "" Or IsNumeric(rup) = FalseThen
Return "Error"
Else
Return (Rupee / 68.64)
End If
End Function

<WebMethod()> _
Public Function RupeesToRiggit(ByVal Rupee As String) As String
Dim rup
rup = Trim(Rupee)
If rup = "" Or IsNumeric(rup) = False Then
Return "Error"
Else
Return (Rupee / 13.67)
End If
End Function

<WebMethod()> _
Public Function RupeesToReal(ByVal Rupee As String) As String
Dim rup
rup = Trim(Rupee)
If rup = "" Or IsNumeric(rup) = False Then
Return "Error"
Else
Return (Rupee/26.7)
End If
End Function
End Class

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Result:
Thus, the Web-Service creation using .Net for currency conversion has been executed
successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:9(ii) WEB SERVICE CREATION USING .NET FOR


Date: TEMPERATURE CONVERSION

Aim:
To create a Web Service program using .NET for temperature conversion.

Procedure:
Step-1: Start->All programs->Microsoft Visual Studio 2010.
Step-2: Select New Project->Visual Basic->WCF Service Application->Filename.
Step-3: A Solution Explorer Window will be displaying on the screen.
Step-4: Right click on the file name and select Add->New Item->Web Service, and then click Add.
Step-5: Within the Web Method type the program for temperature conversion.
Step-6: Execute the Web Service program.

Source Code:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Service
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function FtoC(ByVal Faren As String) As String
Dim f
f = Trim(Replace(Faren, ",", "."))
If f = "" Or IsNumeric(f) = False Then
Return "Error"
Else
Return (((f - 32) / 9) * 5)
End If
End Function

<WebMethod()> _
Public Function CtoF(ByVal Cel As String) As String
Dim c
c = Trim(Replace(Cel, ",", "."))
If c = "" Or IsNumeric(c) = False Then
Return "Error"
Else
Return (((c * 9) / 5) + 32)
End If
End Function
End Class

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

www.Vidyarthiplus.com
www.Vidyarthiplus.com

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Result:
Thus, the Web-Service creation using .Net for temperature conversion has been executed
successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:10(i) JAXB MARSHALING


Date:

Aim:
To create a JAXB Marshaling program for converting Object into XML using Marshaller
interface.

Procedure:
Step-1: Create the process.
Step-2:Create POJO or bind the schema and generate the classes.
Step-3:Create the JAXBContent object.
Step-4:Create the Marshaler objects.
Step-5:Create the content tree by using set methods.
Step-6:Call the marshal method.
Step-7: Stop the process.

Source Code:

Filename: Question.java

importjava.util.List;
importjavax.xml.bind.annotation.XmlAttribute;
importjavax.xml.bind.annotation.XmlElement;
importjavax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Question
{
privateint id;
private String questionname;
private List<Answer> answers;
public Question()
{}
public Question(int id, String questionname, List<Answer> answers)
{
super();
this.id = id;
this.questionname = questionname;
this.answers = answers;
}
@XmlAttribute
publicintgetId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}

www.Vidyarthiplus.com
www.Vidyarthiplus.com

@XmlElement
public String getQuestionname()
{
returnquestionname;
}
public void setQuestionname(String questionname)
{
this.questionname = questionname;
}
@XmlElement
public List<Answer>getAnswers()
{
return answers;
}
public void setAnswers(List<Answer> answers)
{
this.answers = answers;
}
}

Filename: Answer.java

public class Answer


{
privateint id;
private String answername;
private String postedby;
public Answer()
{}
public Answer(int id, String answername, String postedby)
{
super();
this.id = id;
this.answername = answername;
this.postedby = postedby;
}
publicintgetId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getAnswername()
{
returnanswername;
}
public void setAnswername(String answername)
{
this.answername = answername;
}

www.Vidyarthiplus.com
www.Vidyarthiplus.com

public String getPostedby()


{
returnpostedby;
}
public void setPostedby(String postedby)
{
this.postedby = postedby;
}
}

Filename:ObjectToXml.java

importjava.io.FileOutputStream;
importjava.util.ArrayList;
importjavax.xml.bind.JAXBContext;
importjavax.xml.bind.Marshaller;
public class ObjectToXml
{
public static void main(String[] args) throws Exception
{
JAXBContextcontextObj = JAXBContext.newInstance(Question.class);
MarshallermarshallerObj = contextObj.createMarshaller();
marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
Answer ans1=new Answer(101,java is a programming language,ravi);
Answer ans2=new Answer(102,java is a platform,john);
ArrayList<Answer> list=new ArrayList<Answer>();
list.add(ans1);
list.add(ans2);
Question que=new Question(1,What is java?,list);
marshallerObj.marshal(que, new FileOutputStream(Question.xml));
}
}

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Output:

Result:
Thus, the JAXB Marshaling program for converting Object into XML has been executed
successfully.

www.Vidyarthiplus.com
www.Vidyarthiplus.com

Exp No:10(ii) JAXB UNMARSHALING


Date:

Aim:
To create a JAXB UnMarshaling program for converting XML into Object using Unmarshaller
interface.

Procedure:
Step-1: Start the process.
Step-2: Create POJO or bind the schema and generate the classes.
Step-3: Create the JAXBContent object.
Step-4: Create the Unmarshaller objects.
Step-5:Callthe unmarshal method.
Step-6:Use getter methods of POJO to access the data.
Step-7: Stop the process.

Source Code:

Filename: Question.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


<question id="1">
<answers>
<answername>java is a programming language</answername>
<id>101</id>
<postedby>ravi</postedby>
</answers>
<answers>
<answername>java is a platform</answername>
<id>102</id>
<postedby>john</postedby>
</answers>
<questionname>What is java?</questionname>
</question>

Filename: Question.java

importjava.util.List;
importjavax.xml.bind.annotation.XmlAttribute;
importjavax.xml.bind.annotation.XmlElement;
importjavax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Question
{
privateint id;
private String questionname;
private List<Answer> answers;
public Question()
{}

www.Vidyarthiplus.com
www.Vidyarthiplus.com

public Question(int id, String questionname, List<Answer> answers)


{
super();
this.id = id;
this.questionname = questionname;
this.answers = answers;
}
@XmlAttribute
publicintgetId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
@XmlElement
public String getQuestionname()
{
returnquestionname;
}
public void setQuestionname(String questionname)
{
this.questionname = questionname;
}
@XmlElement
public List<Answer>getAnswers()
{
return answers;
}
public void setAnswers(List<Answer> answers)
{
this.answers = answers;
}
}

Filename:Answer.java

public class Answer


{
privateint id;
private String answername;
private String postedby;
public Answer()
{}
public Answer(int id, String answername, String postedby)
{
super();
this.id = id;
this.answername = answername;
this.postedby = postedby;
}

www.Vidyarthiplus.com
www.Vidyarthiplus.com

publicintgetId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getAnswername()
{
returnanswername;
}
public void setAnswername(String answername)
{
this.answername = answername;
}
public String getPostedby()
{
returnpostedby;
}
public void setPostedby(String postedby)
{
this.postedby = postedby;
}
}

Filename: XmlToObject.java

importjava.io.File;
importjava.util.List;
importjavax.xml.bind.JAXBContext;
importjavax.xml.bind.JAXBException;
importjavax.xml.bind.Unmarshaller;
public class XmlToObject
{
public static void main(String[] args)
{
try
{
File file = new File("Question.xml");
JAXBContextjaxbContext = JAXBContext.newInstance(Question.class);
UnmarshallerjaxbUnmarshaller = jaxbContext.createUnmarshaller();
Question que= (Question) jaxbUnmarshaller.unmarshal(file);
System.out.println(que.getId()+" "+que.getQuestionname());
System.out.println("Answers:");
List<Answer> list=que.getAnswers();
for(Answer ans:list)
System.out.println(ans.getId()+" "+ans.getAnswername()+""+ans.getPostedby());
}

www.Vidyarthiplus.com
www.Vidyarthiplus.com

catch (JAXBException e)
{
e.printStackTrace();
}
}
}

Output:

Result:
Thus, the JAXB UnMarshaling program for converting XML into Object has been executed
successfully.

www.Vidyarthiplus.com

Anda mungkin juga menyukai