...
- Add References to System.Runtime.Serialization and System.Net
- Add the nuget package Newtonsoft.Json
- Add a new class file to the project and paste the code from the code generator of the API - you can get this by clicking on the "Generate C#" link on the metadata page:
Create a cookie aware WebClient using this code:
Code Block language c# title Cookie Aware WebClient public class CookieAwareWebClient : WebClient { public CookieAwareWebClient() { CookieContainer = new CookieContainer(); } public CookieContainer CookieContainer { get; private set; } protected override WebRequest GetWebRequest(Uri address) { var request = (HttpWebRequest)base.GetWebRequest(address); request.CookieContainer = CookieContainer; return request; } }
Add the following code:
Code Block language c# title Using WebClient using (var webclient = new CookieAwareWebClient()) { var reqparm = new System.Collections.Specialized.NameValueCollection(); reqparm.Add("username", "api"); reqparm.Add("password", "password"); byte[] responsebytes = webclient.UploadValues("http://api.jiwa.com.au/auth", "POST", reqparm); string responsebody = Encoding.UTF8.GetString(responsebytes); ServiceStack.AuthenticateResponse webClientAuthResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<ServiceStack.AuthenticateResponse>(responsebody); // Read a debtor responsebody = webclient.DownloadString("http://api.jiwa.com.au:80/debtor/1001"); JiwaFinancials.Jiwa.JiwaServiceModel.DebtorGetResponse webClientDebtorGetResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<JiwaFinancials.Jiwa.JiwaServiceModel.DebtorGetResponse>(responsebody); }
...