不包含移动服务的定义

时间:2014-02-06 09:42:54

标签: windows-phone azure-mobile-services

我在windows azure页面上介绍了如何将我的应用程序连接到移动服务,并且我在代码的最后一行中不断收到此错误:“PhoneApp1.App不包含'mobileservice'的定义”。 我添加了对WindowsAzure.MobileServices包的引用,它没有帮助。我该怎么办?

这是我的代码:

namespace PhoneApp1
{

    public class Item
    {
        public string Id { get; set; }
        public string Text { get; set; }
    }

    public partial class Signup_Page : PhoneApplicationPage
    {
        public static MobileServiceClient MobileService = new MobileServiceClient(
            "https://ppmobserv.azure-mobile.net/",
            "kiejvLOaNFeLZKYsFqhPQMzRgXEylc66"
        );

        public Signup_Page()
        {  
            InitializeComponent();
        }

        private async void InsertItem()
        {
            Item item = new Item { Text = "Awesome item" };
            await App.MobileService.GetTable<Item>().InsertAsync(item);
        }

    }
}

1 个答案:

答案 0 :(得分:1)

此部分应放在App.xaml.cs中:

public static MobileServiceClient MobileService = new MobileServiceClient(
        "https://ppmobserv.azure-mobile.net/",
        "kiejvLOaNFeLZKYsFqhPQMzRgXEylc66"
    );

这样您就可以通过以下方式从Signup_Page访问它:

await App.MobileService.GetTable<Item>().InsertAsync(item);

如果您在MobileService而不是App.xaml.cs中定义Signup_Page(上面的第一个代码块),则需要在没有App.前缀的情况下访问它:

await MobileService.GetTable<Item>().InsertAsync(item);