Web Service Testing With .Net 3.16.16 Web Service Testing With .Net Troy Walsh
Overview Web service primer Web service testing tools Microsoft.AspNet.WebApi.Client overview Basic usage Deep dive Takeaways Questions References
What is a Web Service Machine to machine communication using web technologies Client Client Web Server Client Client Client
Request Request URI (Universal Resource Identifier) Header Method Service endpoint *Query string Header Method Get Post/Put Delete *Content/media types *Body
Response Response Status Code Description Header *Body
Web Service Call Header Body Web Server Client Header Status Body
Web Service Clients Popular clients Ready! API (Java based tool) RESTClient (Firefox add-in) Advanced REST client (Chrome extension) Fiddler, Wireshark (diagnostic tools) Microsoft.AspNet.WebApi.Client (C# library) Plus more
Why Microsoft.AspNet.WebApi.Client Real world usage Supported by Microsoft .Net Serialization Licensing/cost Available via Nuget “Easy” to work with
Why Not Microsoft.AspNet.WebApi.Client Already invested in another tool Not a .Net shop Requires development skill Extra work to do negative testing
Basic Usage // Setup http client HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://magenicautomation.azurewebsites.net"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); // Send the request and get back the response HttpResponseMessage response = client.GetAsync("/api/String/1").Result; string result = response.Content.ReadAsStringAsync().Result;
Deep Dive Basic setup Data driving Framework buildout Serialization Models Media type formatters Async Configuration Parallelization
Takeaways Powerful Requires development Not right for every project .Net Serialization Parallelization Requires development Not right for every project
Questions?
References http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from- a-net-client https://msdn.microsoft.com/en-us/library/hh191443.aspx https://msdn.microsoft.com/en-us/library/x6c1kb0s(v=vs.110).aspx http://www.newtonsoft.com/json/help/html/Introduction.htm http://callumhibbert.blogspot.gr/2009/07/data-driven-tests-with- mstest.html https://en.wikipedia.org/wiki/Web_service http://www.asp.net/web-api/overview/security/individual-accounts-in- web-api