Пример #1
0
        public void EtagWorksOnGet()
        {
            HttpClient          client = new HttpClient();
            HttpRequestMessage  request;
            HttpResponseMessage response;

            // Retrieving an object for the first time. Observe that the ETag is NOT in the response headers and
            // the returned payload contains the annotation @odata.etag indicating the ETag associated with that customer.
            request  = new HttpRequestMessage(HttpMethod.Get, ApiUri.ToString() + "/Houses('" + house1guid.ToString("D") + "')");
            response = client.SendAsync(request).Result;
            response.EnsureSuccessStatusCode();
            dynamic house     = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            string  odataEtag = house["@odata.etag"];

            // Retrieving the same object as in the previous request but only if the ETag doesn't match the one
            // specified in the If-None-Match header. We are sending the ETag value that we obtained from the previous
            // request, so we expect to see a 304 (Not Modified) response.
            request = new HttpRequestMessage(HttpMethod.Get, ApiUri.ToString() + "/Houses('" + house1guid.ToString("D") + "')");
            request.Headers.IfNoneMatch.Add(EntityTagHeaderValue.Parse(odataEtag));
            response = client.SendAsync(request).Result;
            Assert.AreEqual(HttpStatusCode.NotModified, response.StatusCode);
        }
Пример #2
0
        /// <summary>
        /// Gets a reference to an HttpClient object to communicate with
        /// </summary>
        /// <param name="url">Base url for the hosted services</param>
        /// <returns>HttpClient object pointing to the given url</returns>
        private HttpClient GetClient()
        {
            if (m_Clients == null)
            {
                m_Clients = new Dictionary <string, HttpClient>();
            }
            string     url    = ApiUri.ToString();
            HttpClient client = null;

            if (m_Clients.ContainsKey(url))
            {
                client = m_Clients[url];
            }
            else
            {
                client = new HttpClient()
                {
                    BaseAddress = new Uri(url)
                };
                m_Clients[url] = client;
            }
            return(client);
        }
Пример #3
0
        private RoomsSoapClient getRoomsApi()
        {
            if (_roomsApi == null)
            {
                _roomsApi = new RoomsSoapClient(new BasicHttpBinding(), new EndpointAddress(ApiUri.ToString()));
            }

            return(_roomsApi);
        }