“请求已经提交。”在 WP8 中使用 Skydrive API

Posted

技术标签:

【中文标题】“请求已经提交。”在 WP8 中使用 Skydrive API【英文标题】:"The request has already been submitted.” while working with Skydrive API in WP8 【发布时间】:2014-01-01 16:06:08 【问题描述】:

我正在尝试使用 SkyDrive API 上传文件。我尝试使用下面的代码。GETAccountInformaiton 和 GetQuotaInformaiton 方法已成功执行但它总是设置此错误“请求已提交。”最后(在字段 lblMessageBar.Text 的 UploadISOFileToSkyDriveAsync() 方法中)。

   private async void GetAccountInformations()
    
        try
        
            LiveOperationResult operationResult = await App.liveConnectClient.GetAsync("me");
            var jsonResult = operationResult.Result as dynamic;
            string firstName = jsonResult.first_name ?? string.Empty;
            string lastName = jsonResult.last_name ?? string.Empty;
            lblMessageBar.Text = "Welcome " + firstName + " " + lastName;
            GetQuotaInformations();
        
        catch (Exception e)
        
            lblMessageBar.Text = e.ToString();
        
    
    private async void GetQuotaInformations()
    
        try
        
            LiveOperationResult operationResult = await App.liveConnectClient.GetAsync("me/skydrive/quota");
            var jsonResult = operationResult.Result as dynamic;
            quota = jsonResult.quota ?? string.Empty;
            available = jsonResult.available ?? string.Empty;
            lblMessageBar.Text = "Available space in bytes: " + ConvertBytesToGigabytes(available).ToString("#.####") + "GB " + "out of bytes " + ConvertBytesToGigabytes(quota).ToString("#.####") + "GB";
            UploadISOFileToSkyDriveAsync();

        
        catch (Exception e)
        
            lblMessageBar.Text = e.ToString();
        
    



    public async void UploadISOFileToSkyDriveAsync()
    
        try
        


            //http://developer.nokia.com/Community/Wiki/SkyDrive_-_How_to_upload_content_on_Windows_Phone
            IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
            StreamWriter Writer = new StreamWriter(new IsolatedStorageFileStream("/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName, FileMode.Append, fileStorage));
            //get the data from local database and write to the isolated file and then use the path of this file to saved it to skydrive..
            ObservableCollection<SavedLocationsTableEntity> SavedLocations = SavedLocationsTableEntity.GetSavedLocations();
            foreach (SavedLocationsTableEntity item in SavedLocations)
            
                Writer.WriteLine(UtilityLib.GetGoogleURL(new System.Device.Location.GeoCoordinate(item.SavedLocationLatitude, item.SavedLocationLongitude, item.SavedLocationAltitude)));
            

            Writer.Close();
            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            
                fileStream = store.OpenFile("/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName, FileMode.OpenOrCreate, FileAccess.Read);

                //strEncryptedFileStream = Encoding.Unicode.GetBytes(fileStream.ToString()).ToString();
                if (fileStream.Length == 0)
                
                    lblMessageBar.Text = "No data to upload to SkyDrive..";
                    return;
                
                fileStream.Close();
            
            //remove previous calls

            var reqList = BackgroundTransferService.Requests.ToList();
            foreach (var req in reqList)
            
                if (req.UploadLocation.Equals(new Uri(MyFilePathInIsoStore, UriKind.Relative)))
                    BackgroundTransferService.Remove(BackgroundTransferService.Find(req.RequestId));
            

            //Make a new call to upload
            LiveOperationResult res = await App.liveConnectClient.BackgroundUploadAsync("me/skydrive", new Uri("/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName, UriKind.Relative), OverwriteOption.Overwrite);
            lblMessageBar.Text = "File " + Constants.SkyDriveSavedLocationsFileName + " uploaded.";
            return;
        
        catch (Exception ex)
        
            lblMessageBar.Text = "Cannot upload to SkyDrive.. " + ex.Message;
            return;

        
    

【问题讨论】:

【参考方案1】:

这里看起来像MyFilePathInIsoStore

if (req.UploadLocation.Equals(new Uri(MyFilePathInIsoStore

这里不等于"/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName

new Uri("/shared/transfers/" + Constants.SkyDriveSavedLocationsFileName, UriKind.Relative)

【讨论】:

永远不会执行循环 foreach(reqList 中的 var req)

以上是关于“请求已经提交。”在 WP8 中使用 Skydrive API的主要内容,如果未能解决你的问题,请参考以下文章

在 wp8 中获取位置的 2 种方法,哪个最好?

如何像在 iOS 中一样在 WP8 中使用 Prefix.pch?

Parse 1.3 与 WP8 的兼容性问题

如何检测背景音乐是​​否在 WP8 中播放?

WP8.1 如何在 C# 中取消后台音频任务

如何防止 WP8 Panorama Control 暂时滑动?