public Stream FixtureCreate(Stream fixtureStream)
        {
            //Get JSON string from stream
            var fixtureJson = new StreamReader(fixtureStream).ReadToEnd();

            //Deserialize
            var contentType = HttpContext.Current.Request.ContentType;
            var fixture = fixtureJson.FromJson<Fixture>(contentType);

            //Store in Mongo DB
            var createdFixture = CreateFixture(fixture);
            createdFixture.Id = null;

            //Serialize
            var createdFixtureJson = createdFixture.ToJson();
            var createdFixtureJsonBytes = Encoding.UTF8.GetBytes(createdFixtureJson);
            var createdFixtureJsonMemoryStream = new MemoryStream(createdFixtureJsonBytes);

            return createdFixtureJsonMemoryStream;
        }
        public Stream FixtureCreate(Stream fixtureStream)
        {
            //Get JSON string from stream
            var fixtureJson = new StreamReader(fixtureStream).ReadToEnd();

            //Deserialize
            var contentType = HttpContext.Current.Request.ContentType;
            var fixture = fixtureJson.FromJson<Fixture>(contentType);

            //Call Internal Service to Store
            const string fixtureCreateUrl = InternalServiceUrl + "fixture";
            var fixtureCreateJson = fixture.ToJson();
            var createdFixtureJson = RestHelper.GetJsonResponse(new Uri(fixtureCreateUrl), fixtureCreateJson, "POST", contentType);

            //Return
            var createdFixtureJsonBytes = Encoding.UTF8.GetBytes(createdFixtureJson);
            var createdFixtureJsonMemoryStream = new MemoryStream(createdFixtureJsonBytes);

            return createdFixtureJsonMemoryStream;
        }
Пример #3
0
        private void bWebHttp_Click(object sender, EventArgs e)
        {
            try
            {

                sw.Reset();
                sw.Start();
                
                WebRequest request = WebRequest.Create("http://localhost:8000/DesktopService/c/20");
                WebResponse ws = request.GetResponse();
                var d = new StreamReader(ws.GetResponseStream(), true).ReadToEnd().UrlDecode();
                //var s = ws.GetResponseStream().Read()
                //var s = d.Substring(1, s.Length - 2);
                var r = d.FromJson<ServiceResult>();
                var s = r.Result.ToString();
                //File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "c.txt", s);
                sw.Stop();
                box.Text += "GetData returned {0} bytes and costed {1} ms\r\n".Fmt(s.Length,
                    sw.ElapsedMilliseconds);
                byte[] bs = Convert.FromBase64String(s);
                using (MemoryStream ms = new MemoryStream(bs))
                {
                    var bmp = Image.FromStream(ms);
                    pic.Image = bmp;
                }
            }
            catch (Exception ex)
            {
                Error.Handle(ex);
            }
        }