当前位置: 首页>>代码示例>>C#>>正文


C# ObjectContent.ReadAsStreamAsync方法代码示例

本文整理汇总了C#中ObjectContent.ReadAsStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContent.ReadAsStreamAsync方法的具体用法?C# ObjectContent.ReadAsStreamAsync怎么用?C# ObjectContent.ReadAsStreamAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObjectContent的用法示例。


在下文中一共展示了ObjectContent.ReadAsStreamAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrimitiveTypesDeserializeAsOData

        public void PrimitiveTypesDeserializeAsOData(string typeString, Type type, object value)
        {
            HttpConfiguration configuration = new HttpConfiguration();

            ODataConventionModelBuilder model = new ODataConventionModelBuilder();
            model.EntitySet<WorkItem>("WorkItems");

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/WorkItems(10)/ID");
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;

            ODataMediaTypeFormatter formatter = CreateFormatter(model.GetEdmModel(), request);
            ObjectContent content = new ObjectContent(type, value, formatter, "application/xml");

            var stream = content.ReadAsStreamAsync().Result;
            Assert.Equal(
                value,
                formatter.ReadFromStreamAsync(type, stream, content, new Mock<IFormatterLogger>().Object).Result);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:18,代码来源:PrimitiveTypesTest.cs

示例2: RoundTripUsingBson

        public void RoundTripUsingBson()
        {
            //Arrange
            var formatters = new[] { new JsonNetFormatter() };
            var fromContact = new Contact { FirstName = "Brad", LastName = "Abrams" };

            // Act
            var fromContent = new ObjectContent<Contact>(fromContact, "application/bson", formatters);
            var contentReadStream = fromContent.ReadAsStreamAsync().Result;
            var newStream = new MemoryStream();
            contentReadStream.Position = 0;
            contentReadStream.CopyTo(newStream);
            newStream.Position = 0;
            var toContent = new ObjectContent<Contact>(new StreamContent(newStream), formatters);
            toContent.Headers.ContentType = new MediaTypeHeaderValue("application/bson");
            var toContact = toContent.ReadAsAsync<Contact>().Result;

            //Arrange
            Assert.AreEqual(fromContact.FirstName, toContact.FirstName);
            Assert.AreEqual(fromContact.LastName, toContact.LastName);
        }
开发者ID:ChrisMissal,项目名称:WcfWebApiContrib,代码行数:21,代码来源:JsonNetTests.cs


注:本文中的ObjectContent.ReadAsStreamAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。