在Azure的移动服务.NET后端(未找到)错误 [英] (Not Found) Error in Azure Mobile Services .NET Backend

本文介绍了在Azure的移动服务.NET后端(未找到)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直坚持与该错误,直到疯狂的阶段......请帮助

我已经创建了一个的Azure移动服务.NET后端,和我现在试图调用从Xamarin Android客户端的功能后

我初始化,然后调用插入异步功能(这些都是我的code代码片段只)

 私有静态IMobileServiceTable<&藤堂GT; _todoMobileServiceTable;公共静态布尔? InitializeAms()
{
    尝试
    {
        CurrentPlatform.Init();
        _mobileServiceClient =新MobileServiceClient(applicationUrl,applicationKey);        _todoMobileServiceTable = _mobileServiceClient.GetTable<&藤堂GT;();        返回true;
    }
    赶上(MalformedURLException的MalformedURLException的)
    {
        ReportHelper.Report(标签,有一个错误创建移动服务验证URL,真实,MalformedURLException的);
    }
    赶上(例外的例外)
    {
        ReportHelper.Report(标签,真正的,异常的Azure移动服务的初始化过程中出现错误);
    }    返回null;
}_todoMobileServiceTable.InsertAsync(待办事项);

调用.InsertAsync(待办事项)时,我得到了以下错误


  

请求无法完成。 (未找到)


N.B:


  • Azure存储客户端不适用于xamarin着呢,我只需要使用这个肮脏的叉子为1岁和iOS的不是机器人(尽管它正常工作与蔚蓝的移动服务是由没有其他选择JavaScript的) https://github.com/zgramana/IOSAzureBlobUploader


  • 它的工作原理,如果我使用浏览器的尝试一下按钮,但是当我把它从xamarin客户端应用程序不起作用。


  • 据从xamarin客户端应用程序工作,如果我使用JavaScript的移动服务


  • 出现此错误无论在本地蔚蓝的移动业务和发表了一份在线


下面是WebApiConfig类

 命名空间Service.Ams
{
    公共静态类WebApiConfig
    {
        公共静态无效的注册()
        {
            //使用这个类来设置的配置选项为您的移动服务
            ConfigOptions选项=新ConfigOptions();            //使用这个类来设置的W​​ebAPI的配置选项
            HttpConfiguration配置= ServiceConfig.Initialize(新ConfigBuilder(选项));            //发展过程中显示在浏览器中的错误,取消以下
            //线。当您部署在生产中使用的服务再评论吧。
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;            Database.SetInitializer(新ServiceAmsInitializer());
        }
    }    公共类ServiceAmsInitializer:ClearDatabaseSchemaIfModelChanges< ServiceAmsDbContext>
    {}
}

下面是TableController类

 命名空间Service.Ams.Controllers
{
    公共类TodoItemController:TableController<&内的TodoItem GT;
    {
        保护覆盖无效初始化(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            ServiceAmsDbContext serviceAmsDbContext =新ServiceAmsDbContext();
            DomainManager =新EntityDomainManager<&内的TodoItem GT;(serviceAmsDbContext,要求,服务);
        }        //获取表/内的TodoItem
        [AuthorizeLevel(AuthorizationLevel.Admin)
        公众的IQueryable<&内的TodoItem GT; GetAllTodoItems()
        {
            返回查询();
        }        //获取表/内的TodoItem / 55D11C86-6EA6-4C44-AA33-337FC9A27525
        [AuthorizeLevel(AuthorizationLevel.Admin)
        公共SingleResult<&内的TodoItem GT; GetTodoItem(字符串ID)
        {
            返回查找(ID);
        }        // PATCH表/内的TodoItem / 55D11C86-6EA6-4C44-AA33-337FC9A27525
        [AuthorizeLevel(AuthorizationLevel.Admin)
        公共任务<&内的TodoItem GT; PatchTodoItem(字符串ID,三角洲和LT;内的TodoItem>补丁)
        {
             返回UpdateAsync(ID,贴片);
        }        // POST表/内的TodoItem / 55D11C86-6EA6-4C44-AA33-337FC9A27525
        [AuthorizeLevel(AuthorizationLevel.Anonymous)
        公共异步任务< IHttpActionResult> PostTodoItem(内的TodoItem项)
        {
            串storageAccountName;
            串storageAccountKey;            //尝试从应用程序设置获得Azure存储帐户令牌。
            如果(
                !(Services.Settings.TryGetValue(STORAG​​E_ACCOUNT_NAME,出storageAccountName)|
                  Services.Settings.TryGetValue(STORAG​​E_ACCOUNT_ACCESS_KEY,出storageAccountKey)))
                Services.Log.Error(无法检索存储帐户的设置。);            //设置的URI Blob存储服务。
            乌里blobEndpoint =新的URI(的String.Format(http://127.0.0.1:10000/{0}/,storageAccountName));            //创建BLOB服务客户端。
            CloudBlobClient blobClient =新CloudBlobClient(blobEndpoint,新StorageCredentials(storageAccountName,storageAccountKey));            //创建一个容器,如果它不存在。
            CloudBlobContainer容器= blobClient.GetContainerReference(item.ContainerName);
            等待container.CreateIfNotExistsAsync();            //创建一个共享访问权限策略。
            BlobContainerPermissions containerPermissions =新BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            };            //启用匿名读取的BLOB。
            container.SetPermissions(containerPermissions);            //定义,给到容器写访问进行5分钟的策略。
            SharedAccessBlobPolicy sasPolicy =新SharedAccessBlobPolicy
            {
                SharedAccessStartTime = DateTime.UtcNow,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(5),
                权限= SharedAccessBlobPermissions.Write
            };            //获取SAS作为一个字符串。
            item.SasQueryString = container.GetSharedAccessSignature(sasPolicy);            //设置用于存储图像的URL。
            item.ImageLqUri =的String.Format({0} {1} / {2},blobEndpoint,item.ContainerName,item.ResourceNameLq);
            item.ImageHqUri =的String.Format({0} {1} / {2},blobEndpoint,item.ContainerName,item.ResourceNameHq);            //完成插入操作。
            当前内的TodoItem等待= InsertAsync(项目);
            返回CreatedAtRoute(表,新{ID = current.Id},电流);
        }        //删除表/内的TodoItem / 55D11C86-6EA6-4C44-AA33-337FC9A27525
        [AuthorizeLevel(AuthorizationLevel.Admin)
        公共任务DeleteTodoItem(字符串ID)
        {
             返回DeleteAsync(ID);
        }    }
}

下面是EntityData类

 命名空间Service.Ams.DataObjects
{
    [表(dbo.TodoItems)]
    公共类内的TodoItem:EntityData
    {
        公共字符串容器名称{搞定;组; }
        公共字符串ResourceNameLq {搞定;组; }
        公共字符串ResourceNameHq {搞定;组; }
        公共字符串SasQueryString {搞定;组; }
        公共字符串ImageLqUri {搞定;组; }
        公共字符串ImageHqUri {搞定;组; }
    }
}


解决方案

有什么办法,你可以得到的HTTP请求看起来像一个转储?

我没有一个Android客户端方便在这里,但我们可以在星期一看看。

亨里克

Been stuck with that error till madness phases ... Please help

I have created an Azure Mobile Service .NET backend, and am now trying to call its Post function from a Xamarin Android client

I initialize and call the Insert async function (these are just snippets from my code)

private static IMobileServiceTable<Todo> _todoMobileServiceTable;

public static bool? InitializeAms()
{
    try
    {
        CurrentPlatform.Init();
        _mobileServiceClient = new MobileServiceClient(applicationUrl, applicationKey);

        _todoMobileServiceTable = _mobileServiceClient.GetTable<Todo>();

        return true;
    }
    catch (MalformedURLException malformedUrlException)
    {
        ReportHelper.Report(Tag, "There was an error creating the Mobile Service. Verify the URL", true, malformedUrlException);
    }
    catch (Exception exception)
    {
        ReportHelper.Report(Tag, "Error occurred during initialization of Azure Mobile Services", true, exception);
    }

    return null;
}

_todoMobileServiceTable.InsertAsync(Todo);

I get the following error when calling .InsertAsync(Todo)

The request could not be completed. (Not Found)

N.B:

  • Azure storage client is not available for xamarin yet, and I have no other choice other than to use this dirty fork which is 1 year old and is made for iOS not Android (although it works fine with azure mobile service javascript) https://github.com/zgramana/IOSAzureBlobUploader

  • It works if I use the browser 'try it out' button but it doesn't work when I call it from the xamarin client app.

  • It works from the xamarin client app if I use the javascript mobile service

  • This error occurs both on the local azure mobile service and the published one online

Here is the WebApiConfig class

namespace Service.Ams
{
    public static class WebApiConfig
    {
        public static void Register()
        {
            // Use this class to set configuration options for your mobile service
            ConfigOptions options = new ConfigOptions();

            // Use this class to set WebAPI configuration options
            HttpConfiguration config = ServiceConfig.Initialize(new ConfigBuilder(options));

            // To display errors in the browser during development, uncomment the following
            // line. Comment it out again when you deploy your service for production use.
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            Database.SetInitializer(new ServiceAmsInitializer());
        }
    }

    public class ServiceAmsInitializer : ClearDatabaseSchemaIfModelChanges<ServiceAmsDbContext>
    {}
}

Here is the TableController class

namespace Service.Ams.Controllers
{
    public class TodoItemController : TableController<TodoItem>
    {
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            ServiceAmsDbContext serviceAmsDbContext = new ServiceAmsDbContext();
            DomainManager = new EntityDomainManager<TodoItem>(serviceAmsDbContext, Request, Services);
        }

        // GET tables/TodoItem
        [AuthorizeLevel(AuthorizationLevel.Admin)]
        public IQueryable<TodoItem> GetAllTodoItems()
        {
            return Query(); 
        }

        // GET tables/TodoItem/55D11C86-6EA6-4C44-AA33-337FC9A27525
        [AuthorizeLevel(AuthorizationLevel.Admin)]
        public SingleResult<TodoItem> GetTodoItem(string id)
        {
            return Lookup(id);
        }

        // PATCH tables/TodoItem/55D11C86-6EA6-4C44-AA33-337FC9A27525
        [AuthorizeLevel(AuthorizationLevel.Admin)]
        public Task<TodoItem> PatchTodoItem(string id, Delta<TodoItem> patch)
        {
             return UpdateAsync(id, patch);
        }

        // POST tables/TodoItem/55D11C86-6EA6-4C44-AA33-337FC9A27525
        [AuthorizeLevel(AuthorizationLevel.Anonymous)]
        public async Task<IHttpActionResult> PostTodoItem(TodoItem item)
        {
            string storageAccountName;
            string storageAccountKey;

            // Try to get the Azure storage account token from app settings.  
            if (
                !(Services.Settings.TryGetValue("STORAGE_ACCOUNT_NAME", out storageAccountName) |
                  Services.Settings.TryGetValue("STORAGE_ACCOUNT_ACCESS_KEY", out storageAccountKey)))
                Services.Log.Error("Could not retrieve storage account settings.");

            // Set the URI for the Blob Storage service.
            Uri blobEndpoint = new Uri(string.Format("http://127.0.0.1:10000/{0}/", storageAccountName));

            // Create the BLOB service client.
            CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentials(storageAccountName, storageAccountKey));

            // Create a container, if it doesn't already exist.
            CloudBlobContainer container = blobClient.GetContainerReference(item.ContainerName);
            await container.CreateIfNotExistsAsync();

            // Create a shared access permission policy. 
            BlobContainerPermissions containerPermissions = new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            };

            // Enable anonymous read access to BLOBs.
            container.SetPermissions(containerPermissions);

            // Define a policy that gives write access to the container for 5 minutes.                                   
            SharedAccessBlobPolicy sasPolicy = new SharedAccessBlobPolicy
            {
                SharedAccessStartTime = DateTime.UtcNow,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(5),
                Permissions = SharedAccessBlobPermissions.Write
            };

            // Get the SAS as a string.
            item.SasQueryString = container.GetSharedAccessSignature(sasPolicy);

            // Set the URL used to store the image.
            item.ImageLqUri = string.Format("{0}{1}/{2}", blobEndpoint, item.ContainerName, item.ResourceNameLq);
            item.ImageHqUri = string.Format("{0}{1}/{2}", blobEndpoint, item.ContainerName, item.ResourceNameHq);

            // Complete the insert operation.
            TodoItem current = await InsertAsync(item);
            return CreatedAtRoute("Tables", new {id = current.Id}, current);
        }

        // DELETE tables/TodoItem/55D11C86-6EA6-4C44-AA33-337FC9A27525
        [AuthorizeLevel(AuthorizationLevel.Admin)]
        public Task DeleteTodoItem(string id)
        {
             return DeleteAsync(id);
        }

    }
}

Here is the EntityData class

namespace Service.Ams.DataObjects
{
    [Table("dbo.TodoItems")]
    public class TodoItem : EntityData
    {
        public string ContainerName { get; set; }
        public string ResourceNameLq { get; set; }
        public string ResourceNameHq { get; set; }
        public string SasQueryString { get; set; }
        public string ImageLqUri { get; set; }
        public string ImageHqUri { get; set; }
    }
}

解决方案

Is there any way you can get a dump of what the HTTP request looks like?

I don't have an android client handy here but we can have a look on Monday.

Henrik

这篇关于在Azure的移动服务.NET后端(未找到)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆