C# 插入到Windows Azure移动服务时发生500内部服务器错误?
当使用从Azure for Mobile Services网站修改的以下代码时,我收到一个“Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException未处理”错误消息:内部服务器错误(500 InternalServerError-详细信息:{“代码”:500,“错误”:“内部服务器错误”}) 我的代码:C# 插入到Windows Azure移动服务时发生500内部服务器错误?,c#,xaml,azure,azure-mobile-services,C#,Xaml,Azure,Azure Mobile Services,当使用从Azure for Mobile Services网站修改的以下代码时,我收到一个“Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException未处理”错误消息:内部服务器错误(500 InternalServerError-详细信息:{“代码”:500,“错误”:“内部服务器错误”}) 我的代码: private MobileServiceCollectionView<pin>
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();
}
以及我的阅读脚本:
function read(query, user, request) {
query.where({ userId: user.userId });
request.execute();
}
正在刷新()中的“wait pinTable.InsertAsync(pin);”行上引发错误。my Azure管理门户中没有错误日志。如果您需要任何其他信息,请询问:)
更新1:我认为我的问题与有关,但这个问题仍然没有答案。我想下面这句话是在制造问题
Pins = pinTable.Where(pin => true).ToCollectionView();
ToCollectionView()代码>始终将计数返回为0。这就是这里的错误。你觉得Josh Twist怎么样
斯塔夫罗斯:我认为下面这句话可以帮助你们的程序顺利运行
List<Pin> Pins = await pinTable.Where(pin => true).ToListAsync();
List Pins=wait pinTable.Where(pin=>true.tolistSync();
我最后只是重做了我所有的代码,它成功了:)但我认为这会有所帮助,所以谢谢:当您在客户端遇到500 InternalServerError时,您可以转到Azure中移动服务的管理控制台,查看日志以了解服务器端引发的异常的更多详细信息。我知道这是固定的,但这些信息可能会帮助其他人看这个问题。
List<Pin> Pins = await pinTable.Where(pin => true).ToListAsync();