2012-09-15 77 views
3

使用从Azure for Mobile Services网站修改的以下代码时,出现“Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException was unhandledMessage:Internal Server Error(500 InternalServerError - Details:{”code“:500,”error“: “内部服务器错误”})“错误。插入到Windows Azure移动服务时500内部服务器错误?

我的代码:

private MobileServiceCollectionView<pin> Pins; 
    private IMobileServiceTable<pin> pinTable = App.MobileService.GetTable<pin>(); 
    public class pin 
    { 
     public string name { get; set; } 
     public long timestamp { get; set; } 
     public string type { get; set; } 
     public object content { get; set; } 
     public string category { get; set; } 
     public string comments { get; set; } 
     public int Id { get; set; } 
    } 
    private LiveConnectSession session; 
    private async System.Threading.Tasks.Task Authenticate() 
    { 
     //authentication code from the Azure site, I deleted it here to save space. 
    } 
    public MainPage() 
    { 
     this.InitializeComponent(); 
    } 
    public long getTimestamp() 
    { 
     //Find unix timestamp (seconds since 01/01/1970) 
     long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks; 
     ticks /= 10000000; //Convert windows ticks to seconds 
     return ticks; 
    } 
    public async Task<bool> Refresh() 
    { 
     List<string> CategoriesMixed = new List<string>(); 
     Pins = pinTable.Where(pin => true).ToCollectionView(); 
     if (Pins.Count < 1) 
     { 
      pin pin = new pin(); 
      pin.category = "Welcome"; 
      pin.content = "Hello, World!"; 
      pin.name = "No Pins :("; 
      pin.comments = string.Empty; 
      pin.timestamp = getTimestamp(); 
      pin.type = "text"; 
      await pinTable.InsertAsync(pin); 
     } 
     else 
     { 
      foreach (pin nowPin in Pins) 
      { 
       await pinTable.DeleteAsync(nowPin); //since I'm still trying to get the inserting pins thing to work, I'm having it delete all pins it finds for the user. 
      } 
     } 
     return true; 
    } 
    /// <summary> 
    /// Invoked when this page is about to be displayed in a Frame. 
    /// </summary> 
    /// <param name="e">Event data that describes how this page was reached. The Parameter 
    /// property is typically used to configure the page.</param> 
    protected override async void OnNavigatedTo(NavigationEventArgs e) 
    { 
     await Authenticate(); 
     await Refresh(); 
    } 

一件事,可能是重要的是,我能一个引脚插入到数据库中,但之后被抛出此错误。另外,如果我在if(Pins.Count < 1)行放置了一个断点,则表明Pins.Count在数据库中存在一个引脚时返回0。

此外,在Azure管理门户,我有以下为我的插入脚本(从http://www.windowsazure.com/en-us/develop/mobile/tutorials/authorize-users-in-scripts-dotnet/):

function insert(item, user, request) { 
    item.userId = user.userId;  
    request.execute(); 
} 

和我读剧本:

function read(query, user, request) { 
    query.where({ userId: user.userId });  
    request.execute(); 
} 

错误正在抛出“等待pinTable.InsertAsync(pin);”在Refresh()中的行。我的Azure管理门户中没有错误日志。如果还有其他需要的信息,请询问:)

更新1:我认为我的问题与http://social.msdn.microsoft.com/Forums/en-US/azuremobile/thread/82ae07a1-5832-4dc9-97d7-1cda1fb33bc2有关,但该问题仍未得到答复。

+0

当你在客户端得到一个500 InternalServerError,你可以去移动服务Azure中的管理控制台,检查日志了解有关服务器端引发的异常的更多详细信息。我知道这是固定的,但这些信息可能会帮助其他人查看这个问题。 – Murven

回答

1

我想下面一行是创造问题

Pins = pinTable.Where(pin => true).ToCollectionView(); 

ToCollectionView();总是返回计数为0。这是错误在这里。你认为Josh Twist怎么样?

斯塔夫罗斯:我认为以下线可以帮助你的程序运行平稳

List<Pin> Pins = await pinTable.Where(pin => true).ToListAsync(); 
+0

我结束了只是重做我的所有代码,它的工作:) 但我认为这会有所帮助,所以谢谢:D – MatthewSot