Docsity

Programming Assignment 3 for Distributed Computing | CS 451, Assignments of Computer Science

Toggle sidebar
bg1
1
CS 451: Distributed Systems
Spring 2007
Programming Assignment #3: Web Services
Due: 12:30 pm, Thursday Mar 29
1. Introduction
In continuing our exploration of various programming models for distributed systems, we will now
consider Web services.
Objectives. After completing this programming assignment, you will be able to:
1. Understand the basic mechanisms by which to develop Web service clients and Services on three
of the major Web services platforms:
o Visual Studio 2005 (C#)
o AXIS2 (Java)
o gSOAP (C/C++)
2. Gain experience with cross-platform development
3. View raw SOAP messages and WS-Security messages
You MUST do this assignment by yourself. While I definitely see the value of working in groups, this
particular assignment is a better learning experience if you do it by yourself. Note: if a particular step in
the assignment is ―not working‖, you can certainly ask your colleagues for help. Of course, ―help‖ does
not mean that they tell you the answer, rather that the help you understand what’s going wrong.
Because this is in the style of a ―Hands-On Lab‖, I strongly encourage you to complete this lab in one
sitting. If you are unable to complete it in one sitting, you may not be able to easily continue where you
left off.
The instructions assume that you’re using a machine in 002a, although you can use your own Windows
XP/Vista machine if you have Visual Studio 2005 installed (Note: this assignment requires two
substantial downloads/installations, so you might just want to use the lab machines). You will also need
to use a Linux machine (such as the ―lava‖ machines – use ―lava001‖, for example).
Also, you are NOT expected to type in these code segments by hand (instead, cut-and-paste them); but
PLEASE make sure that you understand what each step is doing! NOTE: sometimes cut-and-paste
inserts “strange characters” – make sure that the code that is inserted is the same as what appears
in the PDF.
Expected time: 3 hours.
2. Web Services Development on the .NET Framework 3.0
In this first part of the assignment, we will be using the .NET Framework v3.0 from Microsoft (released
Nov 21, 2006). We’ll need both the .NET run-time and the SDK:
1. If you’re using machine in 002a, and the machine is not booted into Windows XP, reboot (when
the ―fedora‖ window appears, you have THREE SECONDS to hit the down arrow so that you can
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Programming Assignment 3 for Distributed Computing | CS 451 and more Assignments Computer Science in PDF only on Docsity!

CS 451: Distributed Systems

Spring 2007

Programming Assignment #3: Web Services

Due: 12:30 pm, Thursday Mar 29

1. Introduction

In continuing our exploration of various programming models for distributed systems, we will now consider Web services.

Objectives. After completing this programming assignment, you will be able to:

  1. Understand the basic mechanisms by which to develop Web service clients and Services on three of the major Web services platforms: o Visual Studio 2005 (C#) o AXIS2 (Java) o gSOAP (C/C++)
  2. Gain experience with cross-platform development
  3. View raw SOAP messages and WS-Security messages

You MUST do this assignment by yourself. While I definitely see the value of working in groups, this particular assignment is a better learning experience if you do it by yourself. Note: if a particular step in the assignment is ―not working‖, you can certainly ask your colleagues for help. Of course, ―help‖ does not mean that they tell you the answer, rather that the help you understand what’s going wrong.

Because this is in the style of a ―Hands-On Lab‖, I strongly encourage you to complete this lab in one sitting. If you are unable to complete it in one sitting, you may not be able to easily continue where you left off.

The instructions assume that you’re using a machine in 002a , although you can use your own Windows XP/Vista machine if you have Visual Studio 2005 installed (Note: this assignment requires two substantial downloads/installations, so you might just want to use the lab machines). You will also need to use a Linux machine (such as the ―lava‖ machines – use ―lava001‖, for example).

Also, you are NOT expected to type in these code segments by hand (instead, cut-and-paste them); but PLEASE make sure that you understand what each step is doing! NOTE: sometimes cut-and-paste inserts “strange characters” – make sure that the code that is inserted is the same as what appears in the PDF.

Expected time: 3 hours.

2. Web Services Development on the .NET Framework 3.

In this first part of the assignment, we will be using the .NET Framework v3.0 from Microsoft (released Nov 21, 2006). We’ll need both the .NET run-time and the SDK:

  1. If you’re using machine in 002a, and the machine is not booted into Windows XP, reboot (when the ―fedora‖ window appears, you have THREE SECONDS to hit the down arrow so that you can

select the OS to boot. Then, select Windows XP, and select the first ―Windows XP‖ again on the next screen).

  1. The .NET 3.0 run-time and the SDK should have already been installed for you. To check: a. .NET 3.0 run-time: look for "Microsoft .NET Framework 3.0" in the "Add or Remove Programs" of the Control Panel. If needed, install via the Web (google for ―.net framework 3.0 redistributable‖) b. SDK: look for ―Microsoft Windows Software Development Kit (6000.0.0)‖ in the "Add or Remove Programs" of the Control Panel. If needed, install via the Web (google for ―windows sdk for vista‖). Make sure the version is ―Orcas_March07CTP‖ (11/7/2006).

2.1 Web Services Development and Deployment on the .NET Framework using Visual

Studio 2005

In this exercise, you will create a simple Web service and client using the .NET Framework 3.0 Windows Communication Foundation (WCF).

  1. Log into ITC’s home directory – this is where you’ll keep your Visual Studio files. A. START  My computer and navigate to c:\program files\Home Directory Login v1.0. and run ―Home‖ (I will assume that this drive is mapped as ―J:‖) 2.Boot Visual Studio 2005: A. START  All Programs  Microsoft Visual Studio 2005  Microsoft Visual Studio 2005 (set ―Visual C# Development Settings‖ as the default)
  2. Create a C# Console Application: A. FILE  new  Project B. Select Visual C# Projects in the Project Types pane. C. Select Console Application in the Templates pane. D. In the Name box, enter CS451PA3Service E. In the Location box, enter ―J:\‖ F. Click OK If the dialog box says ―The project location is not trusted‖, send me email. This should not occur.
  3. Add a reference to the WCF assembly: A. In the Solution Explorer, right-click on the References node, under the CS451PA3Service project node, and select Add Reference. B. Via the ―Browse‖ tab, navigate to c:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Communication Foundation and add System.ServiceModel.dll
  4. Replace the existing code in Program.cs with the following (you can cut-and-paste from the PDF, and then just manually insert newlines):

using System; using System.Collections.Generic; using System.Text; using System.ServiceModel;

namespace HelloService { class Program { static void Main(string[] args) {

//HService.AddServiceEndpoint(typeof(HelloService), // new BasicHttpBinding(), baseURI);

C. Instead of programmatically declaring the service properties, we’re going to use the WCF declarative mechanism: Right-click on the CS451PA3Service in the Solution Explorer, and ―Add  New Item‖ and select ―Application Configuration File‖ (the default name of ―App.config‖ should be used). Replace the entire contents with the following code:

D. Re-compile and re-run the application. If you are successful, then a console app should appear and again display ― YYYY Service at your service‖ (Note: you might have to shut down Visual Studio and restart it to get this step to work). E. With the service running, refresh the IE page. If you are successful, the page should mention something about ―svcutil.exe‖. This is indicating that your service is publishing its service interface.

To hand in for this section:

1. Start an MS Word Document (via START  All Programs  Microsoft Office  Microsoft

Office Word 2003”

_2. Type in “CS 451 PA3” followed by your name(s).

  1. Select the Service console window and hit the “Print Screen” button (upper-right of the_ _keyboard). Note: yes, you must capture the entire screen, not just the console window.
  2. Select the Microsoft Office doc, type in “Part 2.1”, hit “enter”, and then hit “shift-insert”.
  3. Save this doc on J:_

2.2 Writing the .NET Client that consumes the Web Service

In this exercise, you will create a simple .NET client that consumes the Web service created in Exercise

  1. Halt the service by selecting the Service console window and hitting ―enter‖

  2. Add a ―TestClient‖ project to the CS451PA3Service solution by right-clicking on the CS451PA3Service solution node in the Visual Studio Solution Explorer window, select Add, New Project, C# "Console Application"… Name it Client, hit return

  3. In the Client project, add a reference ―System.ServiceModel.dll‖ (click on the ―Recent‖ tab)

  4. Creating the proxy code for the CS451PA3Service: A. Start  Microsoft Windows SDK  CMD Shell B. Cd to your J:\CS451PA3Service\Client directory, and execute the following (note: the service must be running):

svcutil /language:C# /config:app.config http://localhost:8099/hello?wsdl

This will generate two files for you in this directory: ―app.config‖ (which is a configuration file for the client that indicates how to interact with the service), and ―HelloService.cs‖ (which is the proxy code for the service).

C. Select the Service console window, and then hit ―Enter‖ to make the application terminate. D. Add these two files to the Client project (right-click on the ―Client‖ project, and select ―Add  Existing Item‖; change ―Files of type‖ to be ―All Files‖, and add ―app‖ and ―HelloService‖, one at a time). E. Change the ―Program.cs‖ of the Client project to be the following:

using System; using System.Collections.Generic; using System.Text; using System.ServiceModel;

namespace Client { class Program { static void Main(string[] args) { HelloServiceClient p = new HelloServiceClient(); Console.WriteLine("Humphrey .NET client running."); Console.WriteLine(p.sayHi()); } } } F. Replace the ―Humphrey" in the ―Console.WriteLine‖ statement with your name. G. Rebuild the solution H. Re-run the service (note that the window might be buried) I. Run the client by doing the following: Open a new command prompt (start  all programs  accessories  command prompt), and cd into the CS451PA3Service\Client\bin\Debug directory, and execute ―Client.exe‖. If you’re successful, ―Hi!‖ should be printed on the screen.

To hand in for this section:

_1. Select the Client console window (Command Prompt) and hit the “Print Screen” button.

  1. Add this as “Part 2.2” of your MS Word doc._
  1. Recompile the solution, restart the service, and re-run the client.
  2. Stop the service.(Note that this might appear to hang – be patient).
  3. Re-inspect the log via the technique described above.

To hand in for this section:

_1. From the log, how many messages are exchanged?

  1. What is the purpose of each message?(that is, what specification does it conform to?)
  2. Is this message-level security, transport-level security, or both?
  3. What is the encryption method used?
  4. What is the value that is finally returned from the service to the client?_

Select the “Microsoft Service Trace Viewer” window. Select the LAST message logged, show the XML tag, and scroll to the point where your answer to question 5 is shown, and hit “ALT-Print Screen” button. Add this as “Part 2.4” of your MS Word doc, after your answers to the 5 questions above.

3. Web Services Development on Linux with Apache Axis

In the second part of the assignment, we'll compare the development experience gained in the first part on Windows XP via Visual Studio with a development experience on Linux using Apache Axis2. Note that to keep things a little simpler, we're not going to use an IDE on Linux (although there are many available).

3.1 Web Services Deployment on AXIS

  1. Log onto one of the Lava machines (you were given an account on these at the beginning of the semester). START  All Programs  SecureCRT 5.
  2. mkdir PA3; chmod 700 PA3; cd PA
  3. wget http://www.cs.virginia.edu/~humphrey/cs451/Assignments/Assignment3/axis2-1.1.zip
  4. unzip axis2-1.1.zip
  5. create the following Java file, and name it SimpleService.java:

/**

  • The service implementation class */ public class SimpleService {

/**

  • The echo method which will be exposed as the
  • echo operation of the web service */ public String echo(String value) { return ―from Humphrey service‖ + value; } }
  1. Replace the ―Humphrey" in the ―return‖ statement with your name
  2. Each Axis2 service must have a services.xml file which will inform Axis2 about the service. Following is the services.xml file contents for the SimpleService Web service:

SimpleService

  1. Axis2 expects services to be packaged in a certain format. Let’s do that now. a. export JAVA_HOME=/usr/cs/jdk-latest b. export PATH=$JAVA_HOME/bin:$PATH c. mkdir temp

d. javac SimpleService.java -d temp/

e. mkdir temp/META-INF f. cp services.xml temp/META-INF/ g. cd temp

h. jar -cvf SimpleService.aar *

  1. There are two primary hosting environments available for AXIS2 services: [1] Using the SimpleHTTPServer that is available in the Apache Axis2 distribution, or [2] Using Axis2 with Tomcat. We will use the first option. Let’s deploy your new Web service by adding it to the sample Web service directory and telling Axis2 about it: a. export AXIS2_HOME=$HOME/PA3/axis2-1. b. cp $HOME/PA3/temp/SimpleService.aar $AXIS2_HOME/repository/services/ c. edit (emacs, e.g.) $AXIS2_HOME/repository/services/services.list to include your new service
  2. We need to make sure that you use a different port than your colleagues: a. Edit (emacs, e.g.) $AXIS2_HOME/conf/axis2.xml to use a port other than the default, which is 8080 (suggestion: use ―80XY‖, where X and Y are two random digits)
  3. Start up Axis by: sh $AXIS2_HOME/bin/axis2server.sh
  4. Now test it by aiming IE from the Windows machine at the lava machine and port, e.g., http://lava001.cs.virginia.edu:80XY/ a. If it’s working, you should see a list of deployed services. Click on the hyperlink for ―SimpleService‖ and you’ll see the WSDL.

To hand in for this section:

1. Select the “Internet Explorer” window, click on “SimpleService”, scroll down to the bottom of _the WSDL, and hit “ALT-Print Screen” button.

  1. Add this as “Part 3.1” of your MS Word doc._

3.2 Writing the AXIS2 Client that consumes the Web Service

  1. Start up a new SecureCRT terminal to the chosen lava machine.
  2. mkdir PA3/Client
  3. cd PA3/Client
  4. export JAVA_HOME=/usr/cs/jdk-latest
  5. export PATH=$JAVA_HOME/bin:$PATH
  6. export AXIS2_HOME=$HOME/PA3/axis2-1.
  7. sh $AXIS2_HOME/bin/wsdl2java.sh – uri http://localhost:80XY/axis2/services/SimpleService?wsdl
  1. Replace the ―Humphrey" in the ―request.setParam0‖ statement with your name. Also, you might need to replace ―lava001‖.
  2. Re-compile the Client project and re-run the client.

To hand in for this section:

_1. Select the Command Prompt that you ran the client from and hit “ALT-Print Screen” button.

  1. Add this as “Part 3. 3 ” of your MS Word doc._

4. Web Services Development on Linux with gSOAP (C)

4.1 Web Services Deployment on gSOAP

  1. Use the second terminal onto the lava machine (leave the AXIS2 service running in the other window).
  2. cd $HOME/PA
  3. wget http://www.cs.virginia.edu/~humphrey/cs451/Assignments/Assignment3/gsoap_linux_2.7.9d.tar.gz
  4. tar xfz gsoap_linux_2.7.9d.tar.gz
  5. ln – s gsoap-linux-2.7 gsoap-install
  6. Let’s test the client-side to make sure it worked: a. cd $HOME/PA3/gsoap-install/samples/quote b. make c. ./quote IBM (if it works, this returns the current stock price of IBM)
  7. Now let’s test the server-side to make sure it worked: a. cd $HOME/PA3/gsoap-install/samples/webserver b. make c. ./webserver 8190 & (Note: this must be an even-numbered port) d. Now aim Internet Explorer at http://lava001.cs.virginia.edu:8190/ (username: admin, password: guest) e. Now aim Internet Explorer at http://lava001.cs.virginia.edu:8190/test.html f. Now aim Internet Explorer at http://lava001.cs.virginia.edu:8190/webserver.wsdl

To hand in for this section:

_1. Select the Internet Explorer showing “webserver.wsdl” and hit “ALT-Print Screen” button.

  1. Add this as “Part 4.1” of your MS Word doc._

4.2 Consuming the AXIS2 Service via gSOAP client

  1. cd $HOME/PA
  2. mkdir gSOAP-client
  3. cd gSOAP-client
  4. export PATH=$HOME/PA3/gsoap-install/bin:$PATH
  5. wsdl2h – c -o SimpleServiceQuery.h http://lava001.cs.virginia.edu:80XY/axis2/services/SimpleService?wsdl
  6. soapcpp2 -c SimpleServiceQuery.h
  7. create the following C file, and name it SimpleServiceQuery.c

#include "soapH.h" // obtain the generated stub #include "SimpleServiceSOAP11Binding.nsmap" // obtain the generated XML namespace mapping // table for the Simple Service main()

struct soap *soap = soap_new(); struct _ns2__echo ns2__echo; struct _ns2__echoResponse ns2__echoResponse;

ns2__echo.param0 = "Hello there from Humphrey gSOAP client!";

if (soap_call___ns1__echo(soap, NULL, NULL, &ns2__echo, &ns2__echoResponse) == SOAP_OK) printf("Response is %s\n", ns2__echoResponse.return_); else // an error occurred soap_print_fault(soap, stderr); // display the SOAP fault on the stderr stream }

  1. Replace the ―Humphrey" in the ―ns2__echo.param0‖ statement with your name.
  2. cp $HOME/PA3/gsoap-install/stdsoap2.c.
  3. cp $HOME/PA3/gsoap-install/stdsoap2.h.
  4. gcc -o SimpleServiceQuery SimpleServiceQuery.c soapC.c soapClient.c stdsoap2.c
  5. execute the client app by invoking: ./SimpleServiceQuery

To hand in for this section:

_1. Select the Command Prompt that you ran the client from and hit “ALT-Print Screen” button.

  1. Add this as “Part 4.2” of your MS Word doc._

What to hand in AND email

A few additional questions that you must answer:

  1. What are the pros/cons of each of the three Web service environments (.NET, AXIS, gSOAP)?
  2. What are the pros/cons of using XML as a message format for distributed systems?
  3. What parts of the assignment did you particularly like?
  4. What parts of the assignment are particularly dislike or were confusing (which you would like me to explain better)?
  5. How would you improve the assignment?

The due date for this assignment is 12:30pm on Thursday Mar 1. ( Note that the submission requirements are basically the same as last time, except that there is no “part 1”.)

  1. Hand in a paper copy of your submission.
  2. Email an electronic copy of the team’s submission to [email protected] with the subject line ―CS451 Assignment 3 (your name)‖