3

Azure for Mobile Services Web サイトから変更された次のコードを使用すると、「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();
    }

重要なことの 1 つは、データベースにピンを 1 つ挿入できたのに、その後このエラーがスローされたことです。また、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();
}

「await 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 に答える