[英]500 Internal Server Error while inserting to Windows Azure Mobile Services?
When using the following code modified from the Azure for Mobile Services website, I get a "Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException was unhandledMessage: Internal Server Error (500 InternalServerError - Details: {"code":500,"error":"Internal Server Error"})" error. 当使用从Azure移动服务网站修改的以下代码时,我得到“Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException is unhandledMessage:Internal Server Error(500 InternalServerError - Details:{”code“:500,”error“:”Internal服务器错误“})”错误。
My code: 我的代码:
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();
}
One thing that could be important is that I was able to insert one pin into the database, but after that this error is being thrown. 有一件事可能很重要,我能够将一个引脚插入数据库,但之后会抛出此错误。 Also, if I put a breakpoint at the if(Pins.Count < 1) line, it shows that Pins.Count is returning 0 when there is a pin in the database. 此外,如果我在if(Pins.Count <1)行放置一个断点,则表明当数据库中有一个引脚时,Pins.Count返回0。
Also, in the Azure Management Portal, I have the following as my script for Insert (from http://www.windowsazure.com/en-us/develop/mobile/tutorials/authorize-users-in-scripts-dotnet/ ): 此外,在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();
}
and my script for read: 和我的阅读脚本:
function read(query, user, request) {
query.where({ userId: user.userId });
request.execute();
}
The error is being thrown on the "await pinTable.InsertAsync(pin);" 错误是在“await pinTable.InsertAsync(pin);”上引发的。 line within Refresh(). Refresh()中的行。 There are no error logs in my Azure management portal. 我的Azure管理门户中没有错误日志。 If there's any other information you need, just ask :) 如果您需要任何其他信息,请问:)
Update 1: I think my problem is related to http://social.msdn.microsoft.com/Forums/en-US/azuremobile/thread/82ae07a1-5832-4dc9-97d7-1cda1fb33bc2 , but that question is still unanswered. 更新1:我认为我的问题与http://social.msdn.microsoft.com/Forums/en-US/azuremobile/thread/82ae07a1-5832-4dc9-97d7-1cda1fb33bc2有关,但该问题仍然没有答案。
I guess below line is creating problem 我想下面的行正在制造问题
Pins = pinTable.Where(pin => true).ToCollectionView();
ToCollectionView();
always returns count as 0. This is the bug here. 总是返回计数为0.这是这里的错误。 What do you think Josh Twist? 你怎么看Josh Twist?
Stavros: I think below line can help your program to running smooth Stavros:我认为下面的行可以帮助你的程序顺利运行
List<Pin> Pins = await pinTable.Where(pin => true).ToListAsync();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.