|
|
8000XXXX Errors Alerts ASP.NET 2.0 .NET Provider Pattern Basic Language Constructs Themes & Skins (web) Tips & Techniques XML Serialization Classic ASP 1.0 Databases General Concepts Search Engine Optimization (SEO)Search | ASP FAQ Tutorials :: ASP.NET 2.0 :: OnTime 2008 API C# Wrapper OnTime 2008 API C# WrapperOnTime 2008 is a Defect tracking and Agile Development Management system. They have a great API exposed through SOAP web services. But each time that you want to call a service, you have handle instantiating that service, and then every method must take (as it's first parameter) the Security Token (guid) from the Web.Config on the server. I wanted one interface that would simplify these calls so that I could simply say:
So I wrote a wrapper for each of their Service.asmx files. You can download the OnTime 2008 API Wrapper here. All you have to do is to replace the text DefaultNamespace with the actual default namespace from the project that you add the OTW folder to. Behind the ScenesMy main objective here was that I didn't want to have to pass in a Guid to the first parameter of EVERY call to the API. Instead, I wanted to set that Guid once and then simply call other methods that didn't include the SecurityToken parameter. So GetAllProjects(Guid securityToken) was replaced with a static method GetAllProjects().The model implements the Singleton Pattern to automatically instantiate one instance of each ServiceClass (when that service is first access) and to share the Guid centrally in a static class called OTW. The class OTW has a static parameter called SecurityToken which automatically loads itself from the SecurityToken AppSettings (if provided), otherwise, it must be set through code before the first API is called as follows:
How the Wrapper Classes WorkThe wrapper classes take advantage of the fact that the Web Service Reference class is a partial class. The wrapper class simply adds a static singleton instance of the class (which is lazily loaded), and then a series of static methods (which operate on that singleton instance) which are identical to the underlying methods except that they don't have a SecurityToken parameter. Instead, when passing the call to the underlying API, it simply passes the static OTW.SecurityToken in place of the 1st parameter. So, as long as the SecurityToken has been configured in the App.Config, or is set through code before the API is executed, OTW.SecurityToken will have the correct value in it. Now, if that security token ever changes, you don't have to change it in 100's of places, but rather just the one. It also simplifies every call to the API by shrinking the number of parameters required by 1 in every case.In order for this to work, you must follow these simple steps:
Good luck and happy coding. Article Courtesy of EJ Alexandra '---------------------------------------------------------------- Related Articles .NET Provider Pattern .NET Streams Basic Language Constructs FogBugz CSharp API Wrapper Themes & Skins (web) Tips & Techniques XML Serialization |