使用Xamarin studio和Windows Azure连接到数据库
本文关键字:连接 数据库 Azure Windows Xamarin studio 使用 | 更新日期: 2023-09-27 18:28:18
我使用Xamarin Studio和Microsoft Azure创建IOS应用程序。我正在尝试将我在Microsoft Azure Mobile Services中创建的表连接到我的应用程序,但遇到了一些问题。
我在Microsoft Azure门户中创建了一个新的移动服务和一个名为"UsersTable"的新表。然后我转到我的代码并开始连接到表。这是我所拥有的:
用户服务.cs:
using System.Collections.Generic;
using MonoTouch.Foundation;
using System.Threading.Tasks;
using MonoTouch.UIKit;
using System.Net.Http;
using Microsoft.WindowsAzure.MobileServices;
namespace Practice_IOS
{
public class UsersService
{
private MobileServiceClient client;
private IMobileServiceTable<UsersTable> usersTable;
public List<UsersTable> Person { get; private set;}
protected UsersService ()
{
CurrentPlatform.Init ();
Person = new List<UsersTable>();
client = new MobileServiceClient (UsersConstants.ApplicationURL, UsersConstants.ApplicationKey, this);
usersTable = client.GetTable<UsersTable>();
}
}
}
用户表格.cs
using System;
using Newtonsoft.Json;
namespace Practice_IOS
{
public class UsersTable
{
public string Id { get; set; }
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "email")]
public bool Email { get; set; }
[JsonProperty(PropertyName = "password")]
public string Password { get; set; }
}
}
UsersConstants.cs:
using System;
namespace Practice_IOS
{
public static class UsersConstants
{
public const string ApplicationURL = @"https://practiceusersxamatin.azure-mobile.net/";
public const string ApplicationKey = @"SecretKeyGoesHere";
}
}
当我去构建它时,它会进入以下代码行
client = new MobileServiceClient (UsersConstants.ApplicationURL, UsersConstants.ApplicationKey, this);
它告诉我"参数#3无法将"Practice.IOS.UsersService"表达式转换为类型System.Net.Http.HttpMessageHandler[]"。我如何将此作为参数
我正在使用此教程http://azure.microsoft.com/en-us/documentation/articles/partner-xamarin-mobile-services-ios-get-started-data/帮助我尝试连接。
我不熟悉为Azure移动服务客户端需要"this"实例的构造函数重载。你确定你需要第三个参数吗?我一直只使用URL和API密钥作为它们的两个参数。