在WP7中进行同步Http/REST调用? [英] Make synchronous Http/REST call in WP7?

查看:80
本文介绍了在WP7中进行同步Http/REST调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究Windows Phone 7应用程序&试图通过使用HttpWebRequest.GetResponse()进行同步REST调用,但是编译器抱怨GetResponse()不可用.我在HttpWebRequest中找到了BeginGetResponse()和EndGetResponse().但是当我读到这两种方法用于异步调用时.

I have been working on Windows Phone 7 application & was trying to make synchronous REST call by using HttpWebRequest.GetResponse() but the compiler was complaining that the GetResponse() is not available. I found the BeginGetResponse() and EndGetResponse() in HttpWebRequest. But as I read that these two methods are used for asynchronous calls.

我们的设计仅实现为支持同步请求,任何人都可以让我知道是否有任何方法可以在WP7中进行同步调用"

Our design has been implemented to support synchronous request only, could anyone please let me know "Is there any way to make synchronous call in WP7"

推荐答案

您可以通过阻塞AutoResetEvent直到异步调用返回来模拟同步请求. 请参阅此处以获取参考实现.

You can simulate synchronous requests by blocking on an AutoResetEvent until the asynchronous call returns. See here for a reference implementation.

这篇关于在WP7中进行同步Http/REST调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆