使用.net后端的Azure移动服务Not Found错误

时间:2014-04-08 14:10:22

标签: c# azure windows-phone-8 azure-mobile-services

我已经使用.net作为后端创建了新的移动服务。现在,当我尝试运行从门户网站下载的示例WP8项目时。它给了我错误"请求无法完成。 (未找到)"。 这是请求对象

{Method: GET, RequestUri: 'http://barbini.azure-mobile.net/tables/Product', Version: 1.1, Content: <null>, Headers:
{
  X-ZUMO-INSTALLATION-ID: cc027ec3-b2ec-4445-b8a3-50a601a2fb39
  X-ZUMO-APPLICATION: fdArvxSstsNLSZaIPIKFoGkHXxvwHcY36
  Accept: application/json
  User-Agent: ZUMO/1.0
  User-Agent: (lang=Managed; os=Windows Phone; os_version=8.0.0.9903; arch=Win32NT; version=1.0.20402.0)
  X-ZUMO-VERSION: ZUMO/1.0 (lang=Managed; os=Windows Phone; os_version=8.0.0.9903; arch=Win32NT; version=1.0.20402.0)
}}

我的产品类如下

[Serializable]
public class Product : ModelBase
{
    /// <summary>
    /// The id.
    /// </summary>
    private string id;

    /// <summary>
    /// The name.
    /// </summary>
    private string name;

    /// <summary>
    /// The price.
    /// </summary>
    private double price;

    /// <summary>
    /// The is active.
    /// </summary>
    private bool isActive;

    /// <summary>
    /// The product group.
    /// </summary>
    private ProductGroup productGroup;

    /// <summary>
    /// Gets or sets the id.
    /// </summary>
    [JsonProperty("id")]
    public string Id
    {
        get
        {
            return this.id;
        }
        set
        {
            this.id = value; 
            this.RaisePropertyChanged("Id");
        }
    }

    /// <summary>
    /// Gets or sets the name.
    /// </summary>
    /// <value>The name.</value>
    [JsonProperty("name")]   
    public string Name
    {
        get
        {
            return this.name;
        }
        set
        {
            this.name = value;
            this.RaisePropertyChanged("Name");
        }
    }

    /// <summary>
    /// Gets or sets the price.
    /// </summary>
    /// <value>The price.</value>
    [JsonProperty("price")]   
    public double Price
    {
        get
        {
            return price;
        }
        set
        {
            this.price = value; 
            this.RaisePropertyChanged("Price");
        }
    }

    /// <summary>
    /// Gets or sets the is active.
    /// </summary>
    /// <value>The is active.</value>
    [JsonProperty("isactive")]
    public bool IsActive
    {
        get
        {
            return isActive;
        }

        set
        {
            this.isActive = value;
            this.RaisePropertyChanged("IsActive");
        }
    }

    /// <summary>
    /// Gets or sets the product group.
    /// </summary>
    [JsonProperty("productgroup")]
    public ProductGroup ProductGroup
    {
        get
        {
            return this.productGroup;
        }

        set
        {
            this.productGroup = value; 
            this.RaisePropertyChanged("ProductGroup");
        }
    }

}

我甚至尝试删除https并将其设为简单的http。但仍然存在错误。 任何人都可以帮助我出错的地方

由于

1 个答案:

答案 0 :(得分:1)

要在移动服务的.NET后端创建“表”,您需要定义您将使用的实体类型(在您的情况下为Product),并创建一个派生自的类TableController<T>。该类中的泛型参数(T)必须实现ITableData接口,最简单的方法是使类继承自EntityData类。例如,这会在您的服务中为您提供“产品”表:

public class ModelBase : EntityData, INotifyPropertyChanged
{
    // implementation of INPC omitted
}

public class Product : ModelBase
{
    /// <summary>
    /// The name.
    /// </summary>
    private string name;

    /// <summary>
    /// The price.
    /// </summary>
    private double price;

    // other properties omitted for brevity

    /// <summary>
    /// Gets or sets the name.
    /// </summary>
    /// <value>The name.</value>
    [JsonProperty("name")]   
    public string Name
    {
        get
        {
            return this.name;
        }
        set
        {
            this.name = value;
            this.RaisePropertyChanged("Name");
        }
    }

    /// <summary>
    /// Gets or sets the price.
    /// </summary>
    /// <value>The price.</value>
    [JsonProperty("price")]   
    public double Price
    {
        get
        {
            return price;
        }
        set
        {
            this.price = value; 
            this.RaisePropertyChanged("Price");
        }
    }
}

public class ProductController : TableController<Product>
{
    protected override void Initialize(HttpControllerContext controllerContext)
    {
        base.Initialize(controllerContext);
        var context = new TheContextClassInYourService(this.Services.Settings.Schema);
        this.DomainManager = new EntityDomainManager<Product>(context, this.Request, this.Services);
    }

    public IQueryable<Product> GetAll()
    {
        return base.Query();
    }

    public SingleResult<Product> GetOneProduct(string id)
    {
        return base.Lookup(id);
    }

    // insert
    public Task<Product> PostProduct(Product input)
    {
        return base.InsertAsync(input);
    }

    // update
    public Task<Product> PatchProduct(string id, Delta<Product> patch)
    {
        return base.UpdateAsync(id, patch);
    }

    public Task DeleteProduct(string id)
    {
        return base.DeleteAsync(id);
    }
}