Microsoft DotNet WAPI SDK Documentation
Microsoft DotNet WAPI SDK
Draft documentation version
Documentation is partial and not validated !
Integrate WIT-DataCenter plateform from Windows Store, Web ASP.NET or Desktop Apps
Install
Install WAPI SDK nuget package from your project. 3 assemblies are added to your .Net project:- WIT.DataCenter.DTOs.dll:DTOs = Data Tranfer Object = entities return by WAPI
- WIT.DataCenter.SDK.Common.dll: portable library with WAPI Proxy
- WIT.DataCenter.SDK.dll:custom WAPI sdk related to project type
Remark
Even if WAPI Nuget package target all .Net project types (Windows Store, Web ASP.NET or Desktop Apps), installed assemblies will be differents.
Configuration and usage depend from project type:
Windows Store App (8.1)
Configure App credentials
Configure WAPI SDK with your App credentials Your developed Apps.Open
App.xaml.cs
and add row above in App()
constructor replacing YOUR_APP_ID
, YOUR_APP_SECRET
and YOUR_APP_NAME
public App() { this.InitializeComponent(); this.Suspending += OnSuspending; WAPIClient.Current.Initialize("YOUR_APP_ID", "YOUR_APP_SECRET", "YOUR_APP_NAME"); }
Call WAPI Operation
You do not have to take care about WAPIToken. User autentication and autorization workflow is handled by WAPI SDK.That's where the magic stuff occur ! if your App do not have retreived a WAPIToken for current end-user, he is automatically redirected on WIT-DataCenter Autorization Server.
Then WAPIToken is stored in Roaming Application Data for future use after App is closed.
Ex: request all your BusinessAccounts on WIT-DataCenter plateform
// Initialize Operation var operation = new GetBusinessAccountsMy(updatedDate: null); // Request Operation (here BusinessAccountDto array is returned) var response = await WAPIHelper.RequestAsync(operation);
Asp.NET App
Configure App credentials
Configure WAPI SDK with your App credentials Your developed Apps.Open
.Config
and update node client replacing YOUR_APP_ID
, YOUR_APP_SECRET
and YOUR_APP_NAME
client identity="YOUR_APP_ID" secret="YOUR_APP_SECRET" name="YOUR_APP_NAME"
Request a Token
-
When end-user need to access WAPI Operation for the first time, redirect him to WIT-DataCenter autorization server
WAPIClient.Current.RequestAuthorization()
-
On callback, request a definitive WAPIToken for current end-user (method is async)
var wapiToken = await WAPIClient.Current.ProcessAuthorizationAsync()
RemarkView OAuth doumentation for detailed Authorization Code Grant Workflow
-
Store WAPIToken in current end-user repository for future use
Remark
End-user must be autenticated in your WebApp to associate WAPIToken
Call WAPI Operation
You need WAPIToken retreived with above workflow.Ex: request all your BusinessAccounts on WIT-DataCenter plateform
// Get WAPIToken IWAPIToken wapiToken = ... // Initialize Operation var operation = new GetBusinessAccountsMy(updatedDate: null); // Request Operation (here BusinessAccountDto array is returned) var response = await WAPIClient.Current.RequestAsync(operation, wapiToken);
Refresh a Token
-
When
access_token
expiration is imminent, refresh:await WAPIClient.Current.RefreshWAPITokenAsync()
RemarkView OAuth documentation for detailed OAuth 2.0 Refresh workflow
- Store refreshed WAPIToken in current end-user repository