Пример #1
0
        public HttpResponseMessage Post(StudentV1 student)
        {
            students.Add(student);
            var response = Request.CreateResponse(HttpStatusCode.Created);

            //response.Headers.Location = new Uri(Request.RequestUri + student.Id.ToString());
            response.Headers.Location = new Uri(Url.Link("GetStudentById", new { id = student.Id }));
            return(response);
        }
Пример #2
0
 public void UseSameProtocolForDifferentDataType()
 {
     using (FileStream fs = new FileStream($"D:/test.xml", FileMode.Create))
     {
         StudentV1 st1 = new StudentV1
         {
             ID    = 201811428023,
             Name  = "Zhao",
             Email = "*****@*****.**"
         };
         DataContractSerializer szr = new DataContractSerializer(st1.GetType());
         szr.WriteObject(fs, st1);
     }
     using (FileStream fs = new FileStream($"D:/test.xml", FileMode.Open))
     {
         DataContractSerializer szr = new DataContractSerializer(typeof(StudentV2));
         StudentV2 st2 = (StudentV2)szr.ReadObject(fs);
         string    msg = "Information:\n" + $"Name:{st2.StudentName}\n" + $"ID:{st2.StudentID}\n" + $"Email:{st2.StudentEmail}";
         Console.WriteLine(msg);
     }
 }