コード例 #1
0
        public INosSession UpdateSession(INosSession nosSession)
        {
            using(HttpClient httpClient = new HttpClient(_baseAddress)) {
                httpClient.DefaultRequestHeaders.Accept.Add(_json);
                string sessionUri = "session";

                JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                byte[] customerBytes = Encoding.UTF8.GetBytes(jsonSerializer.Serialize(nosSession));
                using (MemoryStream stream = new MemoryStream(customerBytes)) {
                    StreamContent sessionContent = new StreamContent(stream);
                    sessionContent.Headers.ContentType = _json;
                    using (HttpResponseMessage response = httpClient.Put(sessionUri, sessionContent)) {
                        nosSession = jsonSerializer.Deserialize<NosSession>(response.Content.ReadAsString());
                    }
                }
                return nosSession;
            }
        }
コード例 #2
0
        public void TestUpdate()
        {
            using (var webservice = CreateRESTHttpService())
            {
                var client = new HttpClient();
                client.BaseAddress = webservice.BaseUri;

                // Builds: http://localhost:20259/RESTEmployeeService.svc/Update?id=1
                var uri = webservice.Uri("Update?id=1");

                //fake http content
                var keyvalus = new List<KeyValuePair<string, string>>();
                keyvalus.Add(new KeyValuePair<string, string>("EmployeeId", "1"));
                var response = client.Put(uri, new FormUrlEncodedContent(keyvalus));

                Assert.True(response.IsSuccessStatusCode, response.ToString());
                //Console.WriteLine(response.Content.ReadAsString());
                Assert.True(response.Content.ReadAsString().Contains("true"));
            }
        }