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


C# RestTemplate类代码示例

本文整理汇总了C#中RestTemplate的典型用法代码示例。如果您正苦于以下问题:C# RestTemplate类的具体用法?C# RestTemplate怎么用?C# RestTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: SearchButton_Click

        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            // Note that you can also use the NJsonHttpMessageConverter based on Json.NET library
            // that supports getting/setting values from JSON directly,
            // without the need to deserialize/serialize to a .NET class.

            IHttpMessageConverter jsonConverter = new DataContractJsonHttpMessageConverter();
            jsonConverter.SupportedMediaTypes.Add(new MediaType("text", "javascript"));

            RestTemplate template = new RestTemplate();
            template.MessageConverters.Add(jsonConverter);

            #if NET_3_5
            template.GetForObjectAsync<GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
                r =>
                {
                    if (r.Error == null)
                    {
                        this.ResultsItemsControl.ItemsSource = r.Response.Data.Items;
                    }
                }, this.SearchTextBox.Text);
            #else
            // Using Task Parallel Library (TPL)
            var uiScheduler = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext();
            template.GetForObjectAsync<GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}", this.SearchTextBox.Text)
                .ContinueWith(task =>
                {
                    if (!task.IsFaulted)
                    {
                        this.ResultsItemsControl.ItemsSource = task.Result.Data.Items;
                    }
                }, uiScheduler); // execute on UI thread
            #endif
        }
开发者ID:gabrielgreen,项目名称:spring-net-rest,代码行数:34,代码来源:MainWindow.xaml.cs

示例2: RestBucksClient

 public RestBucksClient()
 {
     // Create and configure RestTemplate
     restTemplate = new RestTemplate(BaseUrl);
     DataContractHttpMessageConverter xmlConverter = new DataContractHttpMessageConverter();
     xmlConverter.SupportedMediaTypes = new MediaType[]{ new MediaType("application", "vnd.restbucks+xml") };
     restTemplate.MessageConverters.Add(xmlConverter);
 }
开发者ID:gabrielgreen,项目名称:spring-net-rest,代码行数:8,代码来源:RestBucksClient.cs

示例3: SetUp

        public void SetUp()
        {
            template = new RestTemplate(uri);
            template.MessageConverters = new List<IHttpMessageConverter>();

            webServiceHost = new WebServiceHost(typeof(TestService), new Uri(uri));
            webServiceHost.Open();
        }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:8,代码来源:FeedHttpMessageConverterIntegrationTests.cs

示例4: SetUp

        public void SetUp()
        {
            template = new RestTemplate(uri);
            contentType = new MediaType("text", "plain");

            webServiceHost = new WebServiceHost(typeof(TestService), new Uri(uri));
            webServiceHost.Open();
        }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:8,代码来源:RestTemplateIntegrationTests.cs

示例5: Registration

        public Registration(RestRequestCreator requestCreator)
        {
            _restTemplate = requestCreator.GetRestTemplate();
            
//            // 20141211
//            // temporary
//            // TODO: think about where to move it
//            var tracingControl = new TracingControl("TmxClient_");
        }
开发者ID:MatkoHanus,项目名称:STUPS,代码行数:9,代码来源:Registration.cs

示例6: ConfigureRestTemplate

        // Configure the REST client used to consume LinkedIn API resources
        protected override void ConfigureRestTemplate(RestTemplate restTemplate)
        {
            restTemplate.BaseAddress = API_URI_BASE;

            /*
            // Register custom interceptor to set "x-li-format: json" header 
            restTemplate.RequestInterceptors.Add(new JsonFormatInterceptor());
             */
        }
开发者ID:nsavga,项目名称:spring-net-social,代码行数:10,代码来源:LinkedInTemplate.cs

示例7: CreateServer

        /// <summary>
        /// Creates a <see cref="MockRestServiceServer"/> instance based on the given <see cref="RestTemplate"/>.
        /// </summary>
        /// <param name="restTemplate">The RestTemplate.</param>
        /// <returns>The created server.</returns>
	    public static MockRestServiceServer CreateServer(RestTemplate restTemplate) 
        {
            ArgumentUtils.AssertNotNull(restTemplate, "restTemplate");

		    MockClientHttpRequestFactory mockRequestFactory = new MockClientHttpRequestFactory();
		    restTemplate.RequestFactory = mockRequestFactory;

		    return new MockRestServiceServer(mockRequestFactory);
	    }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:14,代码来源:MockRestServiceServer.cs

示例8: SetUp

        public void SetUp()
        {
            template = new RestTemplate(uri);
            template.MessageConverters = new List<IHttpMessageConverter>();

            contentType = new MediaType("application", "json");

            webServiceHost = new WebServiceHost(typeof(TestService), new Uri(uri));
            webServiceHost.Open();
        }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:10,代码来源:JsonHttpMessageConverterIntegrationTests.cs

示例9: AbstractOAuth1ApiBinding

        /// <summary>
        /// Constructs the API template without user authorization. 
        /// This is useful for accessing operations on a provider's API that do not require user authorization.
        /// </summary>
        protected AbstractOAuth1ApiBinding()
        {
            this.isAuthorized = false;
            this.restTemplate = new RestTemplate();
#if !SILVERLIGHT
            ((WebClientHttpRequestFactory)restTemplate.RequestFactory).Expect100Continue = false;
#endif
            this.restTemplate.MessageConverters = this.GetMessageConverters();
            this.ConfigureRestTemplate(this.restTemplate);
        }
开发者ID:nsavga,项目名称:spring-net-social,代码行数:14,代码来源:AbstractOAuth1ApiBinding.cs

示例10: MovieViewModel

        public MovieViewModel()
        {
            CreateMovieCommand = new DelegateCommand(CreateMovie, CanCreateMovie);
            DeleteMovieCommand = new DelegateCommand(DeleteMovie, CanDeleteMovie);

            template = new RestTemplate("http://localhost:12345/Services/MovieService.svc/");
            template.MessageConverters.Add(new DataContractJsonHttpMessageConverter());

            RefreshMovies();
        }
开发者ID:gabrielgreen,项目名称:spring-net-rest,代码行数:10,代码来源:MovieViewModel.cs

示例11: AbstractOAuth2ApiBinding

        /// <summary>
        /// Constructs the API template with OAuth credentials necessary to perform operations on behalf of a user.
        /// </summary>
        /// <param name="accessToken">The access token.</param>
        protected AbstractOAuth2ApiBinding(String accessToken)
        {
            this.accessToken = accessToken;
            this.restTemplate = new RestTemplate();
#if !SILVERLIGHT
            ((WebClientHttpRequestFactory)restTemplate.RequestFactory).Expect100Continue = false;
#endif
            this.restTemplate.RequestInterceptors.Add(new OAuth2RequestInterceptor(accessToken, this.GetOAuth2Version()));
            this.restTemplate.MessageConverters = this.GetMessageConverters();
            this.ConfigureRestTemplate(this.restTemplate);
        }
开发者ID:nsavga,项目名称:spring-net-social,代码行数:15,代码来源:AbstractOAuth2ApiBinding.cs

示例12: SearchButton_Click

        private void SearchButton_Click(object sender, EventArgs e)
        {
            this.ResultsFlowLayoutPanel.Controls.Clear();

            IHttpMessageConverter njsonConverter = new NJsonHttpMessageConverter();
            njsonConverter.SupportedMediaTypes.Add(new MediaType("text", "javascript"));

            RestTemplate template = new RestTemplate();
            template.MessageConverters.Add(njsonConverter);

            template.GetForObjectAsync<JToken>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
                delegate(RestOperationCompletedEventArgs<JToken> r)
                {
                    if (r.Error == null)
                    {
                        foreach (JToken jToken in r.Response.Value<JToken>("responseData").Value<JArray>("results"))
                        {
                            PictureBox pBox = new PictureBox();
                            pBox.ImageLocation = jToken.Value<string>("tbUrl");
                            pBox.Height = jToken.Value<int>("tbHeight");
                            pBox.Width = jToken.Value<int>("tbWidth");

                            ToolTip tt = new ToolTip();
                            tt.SetToolTip(pBox, jToken.Value<string>("visibleUrl"));

                            this.ResultsFlowLayoutPanel.Controls.Add(pBox);
                        }
                    }
                }, this.SearchTextBox.Text);

            /*
            template.GetForObjectAsync<GImagesResponse>("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={query}",
                delegate(RestOperationCompletedEventArgs<GImagesResponse> r)
                {
                    if (r.Error == null)
                    {
                        foreach (GImage gImage in r.Response.Data.Items)
                        {
                            PictureBox pBox = new PictureBox();
                            pBox.ImageLocation = gImage.ThumbnailUrl;
                            pBox.Height = gImage.ThumbnailHeight;
                            pBox.Width = gImage.ThumbnailWidth;

                            ToolTip tt = new ToolTip();
                            tt.SetToolTip(pBox, gImage.SiteUrl);

                            this.ResultsFlowLayoutPanel.Controls.Add(pBox);
                        }
                    }
                }, this.SearchTextBox.Text);
            */
        }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:52,代码来源:GoogleImages.cs

示例13: CreateRestTemplate

 protected override RestTemplate CreateRestTemplate()
 {
     RestTemplate template = new RestTemplate();
     ((WebClientHttpRequestFactory) template.RequestFactory).Expect100Continue = false;
     IList<IHttpMessageConverter> list = new List<IHttpMessageConverter>(2);
     FormHttpMessageConverter item = new FormHttpMessageConverter {
         SupportedMediaTypes = { MediaType.ALL }
     };
     list.Add(item);
     list.Add(new MsJsonHttpMessageConverter());
     template.MessageConverters = list;
     return template;
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:13,代码来源:WeiboOAuth2Template.cs

示例14: Main

        static void Main(string[] args)
        {
            try
            {
                // Configure RestTemplate by adding the new converter to the default list
                RestTemplate template = new RestTemplate();
                template.MessageConverters.Add(new ImageHttpMessageConverter());

                // Get image from url
#if NET_4_0
                Bitmap nuGetLogo = template.GetForObjectAsync<Bitmap>("http://nuget.org/Content/Images/nugetlogo.png").Result;
#else
                Bitmap nuGetLogo = template.GetForObject<Bitmap>("http://nuget.org/Content/Images/nugetlogo.png");
#endif

                // Save image to disk
                string filename = Path.Combine(Environment.CurrentDirectory, "NuGetLogo.png");
                nuGetLogo.Save(filename);
                Console.WriteLine(String.Format("Saved NuGet logo to '{0}'", filename));
            }
#if NET_4_0
            catch (AggregateException ae)
            {
                ae.Handle(ex =>
                {
                    if (ex is HttpResponseException)
                    {
                        Console.WriteLine(((HttpResponseException)ex).GetResponseBodyAsString());
                        return true;
                    }
                    return false;
                });
            }
#else
            catch (HttpResponseException ex)
            {
                Console.WriteLine(ex.GetResponseBodyAsString());
            }
#endif
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
			finally
			{
				Console.WriteLine("--- hit <return> to quit ---");
				Console.ReadLine();
			}
        }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:49,代码来源:Program.cs

示例15: SetUp

	    public void SetUp() 
        {
            mocks = new MockRepository();
            requestFactory = mocks.StrictMock<IClientHttpRequestFactory>();
            request = mocks.StrictMock<IClientHttpRequest>();
            response = mocks.StrictMock<IClientHttpResponse>();
            errorHandler = mocks.StrictMock<IResponseErrorHandler>();
            converter = mocks.StrictMock<IHttpMessageConverter>();
            
            IList<IHttpMessageConverter> messageConverters = new List<IHttpMessageConverter>(1);
            messageConverters.Add(converter);

            template = new RestTemplate();
            template.RequestFactory = requestFactory;
            template.MessageConverters = messageConverters;
            template.ErrorHandler = errorHandler;
	    }
开发者ID:nsavga,项目名称:spring-net-rest,代码行数:17,代码来源:RestTemplateTests.cs


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