將數據保存在從WCF/Web服務收到的windows phone中。 可能會在某段時間後收到回覆,以便如何處理這種情況。 保存數據是沒有問題的,但如果接收到的數據下旬將數據保存在從WCF/Web服務收到的windows phone中。
0
A
回答
0
您可以使用此代碼(顯示從我的項目中的代碼)如何韓德爾:
public void sendPost(string postData, Action<MyResponse, Exception> callback, CreateResponse creater)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(UrlRequest);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Accept = "application/json";
webRequest.AllowAutoRedirect = true;
webRequest.BeginGetRequestStream(new AsyncCallback(getRequestStreamCallback), new Request()
{
HttpRequest = webRequest,
PostData = postData,
Url = UrlRequest,
CallBack = callback,
Creater = creater
});
}
private void getRequestStreamCallback(IAsyncResult asynchronousResult)
{
var request = (Request)asynchronousResult.AsyncState;
// End the stream request operation
Stream postStream = request.HttpRequest.EndGetRequestStream(asynchronousResult);
byte[] byteArray = Encoding.UTF8.GetBytes(request.PostData);
// Add the post data to the web request
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
// Start the web request
request.HttpRequest.BeginGetResponse(new AsyncCallback(getResponseCallback), request);
}
private void getResponseCallback(IAsyncResult asynchronousResult)
{
var request = (Request)asynchronousResult.AsyncState;
try
{
HttpWebResponse response;
// End the get response operation
response = (HttpWebResponse)request.HttpRequest.EndGetResponse(asynchronousResult);
Stream streamResponse = response.GetResponseStream();
StreamReader streamReader = new StreamReader(streamResponse);
var myResponse = streamReader.ReadToEnd();
streamResponse.Close();
streamReader.Close();
response.Close();
MyResponse response_obj = request.Creater.CreateResponseObj();
using (MemoryStream stream = new MemoryStream(Encoding.Unicode.GetBytes(myResponse)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(response_obj.GetType());
response_obj = (GYResponse)serializer.ReadObject(stream);
if (request.CallBack != null)
{
request.CallBack.Invoke(response_obj, null);
}
}
}
catch (WebException e)
{
if (request.CallBack != null)
{
request.CallBack.Invoke(null, e);
}
}
}
public void getInfo(string uid, Action<MyResponse, Exception> callback)
{
CreateResponse creater = new CreateResponseGetInfo();
string model = "User";
string method = "getInfo";
Params parametrs = new Params();
parametrs.Uid = uid;
//create yor request
string request = getRequestString(model, method, parametrs, Atoken);
sendPost(request, callback, creater);
}
所以,你調用方法,其中發送請求web服務postRequester.getInfo(uid, ResponseHandler)
並使用委託處理結果。
private void ResponseHandler(MyResponse result, Exception error)
{
if (error != null)
{
string err = error.Message;
return;
}
else
{
var infoResponse = result as ResponseGetInfo;
if (infoResponse != null)
{
//result processing..
}
}
}
0
所有你在Windows Phone應用程序使Web請求是異步的。這意味着,您從您的應用程序發出Web請求,並附加一個處理程序來處理響應。在迴應處理程序中,您必須處理迴應並根據需要做任何事情。
相關問題
- 1. 將從Web服務接收的數據存儲在windows phone 7應用程序的隔離存儲中
- 2. Windows Phone 8保存數據
- 3. Backbone.js - 將數據保存到服務器
- 4. 在IIS 7.5中託管WCFweb服務
- 5. 加載行從OData服務到的Windows Phone 8的數據庫
- 6. Windows Phone 8 - 將列表保存到IsolatedStorage
- 7. 將.mp4保存到Windows Phone視頻庫
- 8. 使用Windows Phone將Json數據發送到服務器
- 9. 在Windows Phone 7中,如何將BitmapImage保存到本地存儲?
- 10. Windows Phone 8.1使用javascript保存數據
- 11. 如何將數據從Cognito Sync保存到服務器
- 12. Windows Phone xna遊戲,如何保存從Web服務檢索到的XML
- 13. 如何將文件從數據庫保存到服務器php
- 14. 將數據從外部服務器保存到Parse.com
- 15. 將圖像保存到數據庫並從服務器加載
- 16. 在Windows Azure中保存WCF服務的數據 - 非常基本
- 17. 如何在Windows Phone 7中將Toast通知保存到本地數據庫?
- 18. 將在XMLHttpRequest中收到的數據保存到文件
- 19. 從Windows服務接收數據並將它們顯示給MVC
- 20. Windows服務器活動目錄用戶數據到Windows Phone 7?
- 21. 如何在C#中將BitmapImage保存到StorageFolder中Windows Phone 8
- 22. 保存圖像到本地數據庫在Windows Phone 7
- 23. 如何將angularjs數據保存到服務器的文件中?
- 24. 將TCP服務器數據包保存到C++中的文件
- 25. 如何將服務器保存的數據同步到couchbaselite中
- 26. 從wcfweb服務獲取對象到Android手機
- 27. 如何將數據保存在windows phone 7中的xml文件中
- 28. 如何從服務器發送數據到Windows Phone中的另一臺手機?
- 29. 如何將從datepicker檢索到的日期保存到windows phone 7中的數據庫中?
- 30. 如何將數據保存到服務器上(「在雲端」)?