Ejemplo n.º 1
0
        static void PutCustomer(Uri uri, Customer customer)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

            request.Method      = "PUT";
            request.ContentType = "application/xml";
            using (Stream requestStream = request.GetRequestStream())
            {
                customerSerializer.WriteObject(requestStream, customer);
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream responseStream = response.GetResponseStream())
            {
                Customer updatedItem = (Customer)customerSerializer.ReadObject(responseStream);
                Console.WriteLine(updatedItem.ToString());
            }
            response.Close();
        }
Ejemplo n.º 2
0
        static Uri PostCustomer(Uri uri, Customer customer)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

            request.Method      = "POST";
            request.ContentType = "application/xml";
            using (Stream requestStream = request.GetRequestStream())
            {
                customerSerializer.WriteObject(requestStream, customer);
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (Stream responseStream = response.GetResponseStream())
            {
                Customer createdItem = (Customer)customerSerializer.ReadObject(responseStream);
                Console.WriteLine(createdItem.ToString());
            }
            response.Close();
            return(new Uri(response.Headers[HttpResponseHeader.Location]));
        }