3

使用从 Azure for Mobile Services 网站修改的以下代码时,我收到“Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException was unhandledMessage: Internal Server Error (500 InternalServerError - Details: {"code":500,"error":"Internal服务器错误“})”错误。

我的代码:

    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) 行设置断点,则表明当数据库中有 pin 时 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有关,但这个问题仍未得到解答。

4

1 回答 1

1

我猜下面的行正在制造问题

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

ToCollectionView();总是返回计数为 0。这是这里的错误。你觉得乔什·特威斯特怎么样?

Stavros:我认为下面这行可以帮助您的程序顺利运行

List<Pin> Pins = await pinTable.Where(pin => true).ToListAsync(); 
于 2012-09-26T01:49:53.193 回答