DPS907 WSA500 Assignment 12

Create a legacy SOAP XML web service server app, and a separate client app that can work with a SOAP XML web service. This is the final assignment in the fall academic term.

Read/skim all of this document before you begin work.

 

Due date

Wednesday, December 7, 2016, at 11:00pm ET

Grade value: 4% of your final course grade

If you wish to submit the assignment before the due date and time, you can do that.

 

Objective(s)

Demonstrate that you can interact with a web service, using two different kinds of clients.

 

Introduction to the problem to be solved

Adapt an existing and working modern web service app, by adding a legacy SOAP XML web service.

Then, create a new web app, which will act as a client app. It will be able to call into a legacy web service.

 

Specifications overview and work plan

The following specifications apply to all of your assignments:

  • Follows best practices
  • Implements the recommended system design guidance
  • Customized appearance on the landing web page

For this assignment, here is what we’re looking for:

  • SOAP XML web service – server app – that works with data from the Chinook sample database
  • WSA500 – client MVC web app, that calls into the server above
  • DPS907 – client MVC web app, that calls into a public web server at the College

 

During the class/session, your professor will help you get started and make progress on this assignment.

Every week, in the computer-lab class/session, your teacher will record a grade when you complete a specific small portion of the assignment. We call this “in-class grading”.

The in-class grading will be announced in-class by your professor.

 

Getting started

In the course’s code example repository, in the “Templates and solutions” folder, you will see a sample solution for Assignment 5. You can use that as the base for your “server” app. We suggest that you rename the root folder (in the file system) to “Assign12Server”. (That will make it easier for you to identify it later.)

Next, create a new ASP.NET Web Application, as an MVC web app, with no user authentication/security. We suggest that its name will be “Assign12Client”. Personalize the Index view of the Home controller with your own name etc.

 

SOAP XML web service – server

As noted above, you can use the professor’s Assignment 5 sample solution as the base for your server app. Read the specifications again to refresh your memory about its purpose and functionality.

DPS907 WSA500 Assignment 5 (Fall 2016 academic term)

Build/compile, then run the app to ensure that it works correctly. Test with Fiddler.

Personalize the Index view of the Home controller with your own name etc.

Use the technique you learned in this week’s notes to add a WCF Service to the root of the project. The name of your new WCF Service should be: A12Service.svc

 

Use cases for the A12Service.svc

In the base app, the modern Web API controllers handle these use cases:

Customer:

  • Get all
  • Get one
  • Add new
  • Edit existing
  • Command, to set/configure the support rep (employee)

Invoice:

  • Get all

 

In the interface – IA12Service – declare methods that implement the use cases. We suggest that you use method names that are similar to what is found in the Manager class (e.g. CustomerGetAll(), CustomerGetById(), etc.) That way they will show up together – alphabetically – on IntelliSense and other lists.

Then, in the inheriting class, implement the methods in the interface. We recommend:

  • Follow the coding suggestions seen in this week’s code examples
  • Blend in the differences that you have learned about this new class (e.g. return types)

 

One big difference in the inheriting class: It does not have MVC/Web API style model binding. In other words, “ModelState.IsValid” is not available. However, we can add this functionality (yay!). How? Look at this week’s code example, and study the AddEmployee() method in its service class. Notice this code:

var vc = new ValidationContext(newItem, null, null);
var modelStateIsValid = Validator.TryValidateObject(newItem, vc, null, true);

if (modelStateIsValid)
  {
    // etc.

 

Make sure that you use that technique for the methods that need model validation.

 

Test your work

Test your work on Assign12Server by using the WCFTestClient.exe program.

 

SOAP XML web service client – WSA500

This section will be done by WSA500 students. 

Now, work with the Assign12Client web app project.

Use the technique you learned in this week’s notes to add a service reference, to the “server” app that you created above. We suggest that the “Namespace” name be something short and noticeable, maybe “Chinook”.

In the new Manager class, add methods that implement these two (2) use cases for the Customer entity collection:

  • Get all
  • Get one

The methods will call out to the SOAP XML web service, and return an object or collection (or null).

Next, create a Customers (MVC web app) controller. Implement its “get all” and “get one” methods, with views. Add a link to the list-of-customers resource to the app’s menu.

Here’s what the “get all” view looks like. Click an image to open it full-size in a new tab/window. The first image was generated by the view scaffolder. The second image shows the result of some view editing, to group and gather some related information together, to produce a more readable result.

customers-all-ugly

Better version:

customers-all-nice

 

Here’s what the “get one” view looks like. The first image was generated by the view scaffolder. The second image shows the result of some view editing, to group and gather some related information together, to produce a more readable result.

customer-one-ugly

Better version:

customer-one-nice

 

SOAP XML web service client – DPS907

This section will be done by DPS907 students.

Now, work with the Assign12Client web app project.

It will call out to two different web services:

  1. A modern web service, and
  2. A legacy web service

The modern web services will deliver data about courses in academic programs that are offered by the School of ICT.

The legacy web service will deliver an official course outline for a specific course, selected from the data that’s returned by the modern web service.

 

Calling the modern web service

The School of ICT is in the process of building a public API. The future (near-term) vision is that it will deliver hypermedia representations of assets that will be useful to the School of ICT community (students, faculty, and admin staff).

At the present time, we have published resources for academic programs, and courses. In this part of the assignment, we will use the courses resource. We can use the /api/courses to get a collection of all courses. However, for this assignment, we will be interested only in the courses in the BSD program. This collection is available here:

https://ict.senecacollege.ca/api/courses/bsd

Use Fiddler or JSON Formatter to view the data. Then, create a resource model class (e.g. CourseBase) that looks like the data returned by the web service. (The DateCreated and DataRetired properties will be C# DateTime types.)

Now, in the Manager class, use the technique that you learned last week and in Assignment 11 to call out to a modern web service, and handle the result. The result – a collection of courses for the BSD program – will be used in the “get all” user interface, to render in a list. (It would be nice to sort the list somehow.)

Next, create a Courses (MVC web app) controller. Implement its “get all” method, with view. Add a link to the list-of-courses resource to the app’s menu. We will need the scaffolded Details hyperlink, but not the Edit or Delete hyperlinks.

Here’s what the “get all” view looks like. Click an image to open it full-size in a new tab/window. The first image was generated by the view scaffolder. The second image shows the result of some view editing, to group and gather some related information together, to produce a more readable result.

courses-all-ugly

Better version:

courses-all-nice

 

Calling the legacy web service

The College has a system that maintains official course outlines for all courses offered, at all campuses, by all Schools (academic service organizational units). The system provides data to many other systems, including the College’s public web site. Its data can be accessed by a browser client (for rendering in a browser), or by an HTTP client (for whatever it wants to do), through a public web service.

As noted above, the public web service will deliver an official course outline for a specific course. It is a legacy SOAP XML web service, written originally in Java by using one of its web service kits/frameworks. When called, it needs the following data:

  • Course code (e.g. DPS907)
  • Academic term code (e.g. 20163 as a string)
  • School code (e.g. SICT)

For your information only, the academic term code is a string. The year is its first four digits. The last digit is 1 for winter, 2 for summer, and 3 for fall. So, the Fall 2016 academic term code is “20163”, as a string.

If you look at the course outline for this DPS907 course, as published on the School of ICT web site, you will notice lots of text content, including course description, credit status, topic outline, and so on. Most of the text content is HTML. The page is built by calling the legacy web service, and then pouring the data into containers (<div> elements) on page that matches the formatting of our School of ICT web site.

This is the task that you will do – call out to the legacy web service, and render the returned content into an ASP.NET MVC web app page. How can you get started?

First, you will need the URL to the web service’s WSDL document, shown below. You can use a browser to view the document, and of course you will need the URL to complete the next step.

http://www.senecacollege.ca/ssos/services/SubjectOutlineService?wsdl

Next, use the technique you learned in this week’s notes to add a service reference, to the “server” app that you created above. We suggest that the “Namespace” name be something short and noticeable, maybe “SSOS”. (For your information, SSOS is the initialism for the central system that maintains the course outlines, Seneca Subject Outline System.)

Important edit or fix that you must do:

The “add service reference” task creates four (4) “bindings” for different ways to contact the web service. These are added to the Web.config file, near the bottom.

We need only the first one, named “SubjectOutlineServiceHttpSoap11Endpoint”.

Comment out (or remove) the other three.

 

Resource model, manager, controller, view

The resource model for the course outline object was created by the add-service-reference task.

In the Manager class, add a method that will accept a course code parameter, and use it to call out to the SOAP XML web service, and return a course outline object (or null if not found). Enclose the call in a try-catch statement.

What does it mean if the call returns null?

It means that the course does not have a fall-term outline (i.e. academic term code 20163). For example, BTI420 is a winter-term course. It does NOT have a fall-term outline.

Can you fix this?

Yes. You can implement what we did on the School of ICT web site – a sequence of calls, with different academic term codes. Here’s the logic:

1. Attempt to call 20163
2. If null, attempt to call the next academic term, 20171
3. If null, attempt to call the previous academic term, 20162
4. If null, attempt to call the previous-previous academic term, 20161
5. If null, return null

 

Next, in the Courses (MVC web app) controller, implement its “get one” method, with view. The view’s “Model class” will be the SSOS namespaces’s SubjectOutline class.

Important notice: Many of the values in the SubjectOutline object are stored as HTML text. If you attempt to render this content on a view, the Razor view engine, as a safety feature, encodes the text content. The result is that you will see angle brackets. Fixable? Yes. How? Render the value by using the Html.Raw() helper, instead of Html.DisplayFor().

Invest a few minutes and improve the appearance of the view/page. One thing that would be nice to do would be to replace the titles used in the <dd> elements. How? Editing the view, or creating a resource model with data annotations, using AutoMapper, and so on. Editing the view is easier at this point in time. (Can you add data annotations to the generated SubjectOutline class? Let’s just assume that the answer is “no”. That class is generated, and we’re not supposed to edit it.)

Here’s what the “get one” view looks like. Click an image to open it full-size in a new tab/window. The first image was generated by the view scaffolder. The second image shows the result of some reorganization activity, to produce a more readable result.

course-one-ugly

Better version:

course-one-nice

 

Testing your work

If your client app works correctly, then your work has been tested. For this assignment, we do NOT use Fiddler.

 

Reminder about academic honesty

You must comply with the College’s academic honesty policy.

Although you may interact and collaborate with others, you must submit your own work.

 

Submitting your work

This Assignment 12 has a modified submission process (and is similar to the process for the previous Assignment 11).

We need both projects to be able to grade your work.

Therefore, here is the modified procedure:

  1. Make copies of both projects
  2. For each project, remove its packages, bin, and obj folders
  3. Zip both projects together (in one zip file), and upload to the designated location on My.Seneca/Blackboard before the due date-and-time

 

For example, assume that you are currently viewing a folder named “A12” in File Explorer.

It should have these two sub-folders:

  1. Assign12Server
  2. Assign12Client

Select both folders, then zip them into one zip file result.

 

Appendix: Troubleshooting the use of the SSOS service

If you have errors when attempting to use the SSOS service, the following information may be useful.

If you compose your “getOutline()” method call with bad data, the service will respond with an error message that can be misleading. For example, it may respond with the following “not found” message. Click to view the image full-size in a new tab/window:

call-error-message

 

Use the debugger to inspect the data that you pass to the “getOutline” method call.

Alternatively, you can use the “WCF Test Client” app to interact with the SSOS service.

First, start the app, by running the following command at the Windows+R window or a command line:


"c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\wcftestclient.exe"

 

Next, in the app’s File > Add Service dialog, enter the URL of the WSDL document:

http://www.senecacollege.ca/ssos/services/SubjectOutlineService?wsdl

 

After it loads, you will see four bindings. Similar to what you noted earlier, we are interested in the first binding. Double-click its “getOutline()” method. On the upper-right “Request” panel, you will see the data items that you must send. Fill in the data, and click the Invoke button.

The next two images are the screen captures for the procedure described in the previous paragraph. Click to view each image full-size in a new tab/window:

call-wcftestclient-setup

After invocation:

call-wcftestclient-execution

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

%d bloggers like this: