Reputation: 41
I am calling a webservice to send json data by post method. Here is the code for that:
string sample_url = "mywebservice/createsample;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sample_url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = new CookieContainer();
CookieCollection cookcol = new CookieCollection();
cookcol.Add(cookie);
string body= json data
byte[] postBytes = Encoding.UTF8.GetBytes(body);
request.ContentLength = postBytes.Length;
Stream postStream = request.GetRequestStream();
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Close();
WebResponse response = request.GetResponse();
string satus = ((HttpWebResponse)response).StatusDescription;
postStream = response.GetResponseStream();
StreamReader reader = new StreamReader(postStream);
I need to get some timestamp around this webservice request and response as the service seems quite slow. How do I put the countdown timer around this? Thanks for your response.
Upvotes: 0
Views: 143
Reputation: 3769
Beware that you aren't testing your own network latency as well. If you are interested specifically in how long each service call takes, you should probably use a Stopwatch
as per @nvoigt answer, but put this round your service implementation method.
Upvotes: 0