If you have taken a peak at the source code in CodePlex lately, you may have noticed a new library project called LtiLibrary. I’m slowly pulling the LTI specific code out of Consumer (and eventually Provider) to make it easier to explain the code, and to make it easier to reuse.
Today I worked on the OutcomesController. This is the ApiController that implements the consumer side of the LTI 1.1 Basic Outcomes Service which is used to receive scores (grades, outcomes) from the provider.
I chose to implement the controller as an ApiController because MVC handles all the serialization and deserialization for me once I add the schema (which you can download from the IMS website as part of the LTI 1.1 specification) and tell MVC to use the XmlFormatter,
When the controller was part of the Consumer project, I mixed Consumer-specific code such as accessing the consumer database, with LTI code such as handling each outcome request. Since the outcome should eventually be saved in the database, I decided to implement the service as an abstract class in LtiLibrary called OutcomesControllerBase.
OutcomesServiceBase implements the only endpoint (a POST to api/outcomes). The consumer then implements a concrete OutcomesController which inherits from OutcomesServiceBase and implements 4 events handlers:
- OnReplaceResult – Raised when the provider wants to save or update a result
- OnReadResult – Raised when the provider wants to read a result
- OnDeleteResult – Raised when the provider wants to delete a result
- OnGetConsumerSecrets – Raised when the base class is authenticating the request
Each handler is quite short and only has to deal with implementation specific details such as saving the score in the database. For example,
To recap…if you want to add support for Basic Outcomes to your .NET consumer, follow these steps:
- Add the LtiLibrary project to your solution and reference LtiLibrary in your project.
- Create an OutcomesController that inherits from OutcomesControllerBase and implement the 4 handlers.
- Enable XmlSerialization in WebApiConfig.
That will turn your LTI 1.0 consumer into an LTI 1.1 consumer.