سؤال

I've created new mobile service with .net as backend. Now when I try to run the sample WP8 project that I downloaded from the portal. It gives me the error "The request could not be completed. (Not Found)". This is the request object

{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)
}}

And my product class is as follows

[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");
        }
    }

}

I even tried to remove https and made it simple http. But still the error persists. Can anyone help where I m going wrong

Thanks

هل كانت مفيدة؟

المحلول

To create a "table" in the .NET backend of mobile services you need to both define the entity type which you'll use (in your case, Product), and also create a class which derives from TableController<T>. The generic parameter (T) in that class must implement the ITableData interface, and the easiest way to do that is to make the class inherit from the EntityData class. For example, this would give you a "product" table in your service:

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);
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top