【问题标题】:does not contain a definiton for mobileservice不包含移动服务的定义
【发布时间】:2014-02-06 22:45:25
【问题描述】:

我按照 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);
        }

    }
}

【问题讨论】:

标签: windows-phone azure-mobile-services


【解决方案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(上面的第一个代码块)的定义放在Signup_Page而不是App.xaml.cs中,你需要在没有App.前缀的情况下访问它:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-08
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 2021-04-11
    相关资源
    最近更新 更多