• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# RestTemplate类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GetRestTemplate

        public virtual RestTemplate GetRestTemplate()
        {
            if (null != _restTemplate) return _restTemplate;
            _restTemplate = new RestTemplate(ClientSettings.Instance.ServerUrl);
            // 20150316
            // _restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter());
            // 20150609
            // _restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter() as IHttpMessageConverter);
            _restTemplate.MessageConverters.Add(new NJsonHttpMessageConverter());
            _restTemplate.MessageConverters.Add(new XElementHttpMessageConverter());
            
            _restTemplate.MessageConverters.Add(new XmlSerializableHttpMessageConverter());
            _restTemplate.MessageConverters.Add(new ResourceHttpMessageConverter());
            _restTemplate.MessageConverters.Add(new StringHttpMessageConverter());

            // 20150604
            var requestFactory = new WebClientHttpRequestFactory {Timeout = 600000};
            _restTemplate.RequestFactory = requestFactory;

            return _restTemplate;
        }
开发者ID:MatkoHanus,项目名称:STUPS,代码行数:21,代码来源:RestRequestCreator.cs


示例17: RestClient

        public RestClient(string url = null)
        {
            string BaseUrl = string.Empty;
            var httpUrl = Properties.Settings.Default.HttpUrl;
            if (!string.IsNullOrEmpty(httpUrl))
            {
                BaseUrl = httpUrl;
            }
            else
            {
                BaseUrl = RestClient.httpUrl;
                Properties.Settings.Default.HttpUrl = RestClient.httpUrl;
                Properties.Settings.Default.Save();
            }

            BaseUrl = url ?? BaseUrl;

            restTemplate = new RestTemplate(BaseUrl);
            IHttpMessageConverter jsonConverter = new DataContractJsonHttpMessageConverter();
            jsonConverter.SupportedMediaTypes.Add(MediaType.APPLICATION_JSON);
            restTemplate.MessageConverters.Add(jsonConverter);
        }
开发者ID:Guoyingbin,项目名称:Automation.Plugins,代码行数:22,代码来源:RestClient.cs


示例18: Search

        public IList<IStreamableTrack> Search(string searchTerm)
        {
            RestTemplate template = new RestTemplate("http://api.soundcloud.com");
            template.MessageConverters.Add(new DataContractJsonHttpMessageConverter());

            IDictionary<string,object> vars = new Dictionary<string, object>();
            vars.Add("client_id", playerID);
            vars.Add("term", searchTerm);

            var tracks = template.GetForObject<List<Track>>("/tracks.json?client_id={client_id}&order=hotness&q={term}", vars);

            // Remove any tracks that aren't streamable
            tracks.RemoveAll(track => !track.Streamable);

            foreach (var track in tracks)
            {
                // Dodgy hack for now
                track.StreamURL = track.StreamURL + "?client_id=" + playerID;
            }

            return tracks.ConvertAll(input => (IStreamableTrack) input);
        }
开发者ID:dowlingw,项目名称:dasplayer,代码行数:22,代码来源:SoundCloudProvider.cs


示例19: MediaTemplate

		public MediaTemplate(string applicationNamespace, RestTemplate restTemplate, bool isAuthorized)
			: base(applicationNamespace, restTemplate, isAuthorized)
		{
		}
开发者ID:kisspa,项目名称:spring-net-social-facebook,代码行数:4,代码来源:MediaTemplate.cs


示例20: ConfigureRestTemplate

 // Configure the REST client used to consume Twitter API resources
 protected override void ConfigureRestTemplate(RestTemplate restTemplate)
 {
     restTemplate.BaseAddress = API_URI_BASE;
 }
开发者ID:lijinglue,项目名称:spring-net-social,代码行数:5,代码来源:TwitterTemplate.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# RestTestHarness类代码示例发布时间:2022-05-24
下一篇:
C# RestSharp类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap