Azure移动服务UpdateAsync给我404错误

时间:2019-06-22 21:34:30

标签: xamarin xamarin.forms azure-mobile-services

我正在处理xamarin表格并使用azure移动服务。当我尝试更新记录时,UpdateAsync无法正常工作,并给我404错误。

在调试时,我注意到调试器中的以下行:

<b> Requested URL: </b>/tables/Customer/10k<br><br>

10k是ID。

当我将邮递员与上面的链接一起使用时,它会带回我同样的404错误。但是,如果我使用链接/tables/Customer?id=10k,它将在邮递员中工作。

这是来自VS的错误消息。

Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: <!DOCTYPE html>
        <html>
            <head>
                <title>The resource cannot be found.</title>
                <meta name="viewport" content="width=device-width" />
            </head>

            <body bgcolor="white">

                    <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

                    <h2> <i>The resource cannot be found.</i> </h2></span>

                    <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

                    <b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. &nbsp;Please review the following URL and make sure that it is spelled correctly.
                    <br><br>

                    <b> Requested URL: </b>/tables/Customer/10k<br><br>

                    <hr width=100% size=1 color=silver>

                    <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0

                    </font>

            </body>
        </html>
        <!-- 
        [HttpException]: The controller for path &#39;/tables/Customer/10k&#39; was not found or does not implement IController.
           at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
           at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
           at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
           at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
           at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
           at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
           at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
           at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
           at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
        --><!--
        This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using &lt;customErrors mode="Off"/&gt;. Consider using &lt;customErrors mode="On"/&gt; or &lt;customErrors mode="RemoteOnly"/&gt; in production environments.-->

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,但遇到另一个问题。

我将这行代码放在客户控制器的顶部

[Route("tables/Customer")]

我将其删除并进行了编辑

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

对此

config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "tables/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

但是现在当我从客户端更新时,它给了我错误的请求错误。

更新

我修复了错误的请求错误。 在我的后端客户课程中,我有约会时间吗?并且在我的客户客户类中,我有日期时间..我删除了?

现在我遇到内部服务器错误。

更新2

在我的数据库中,我试图更新的记录有一些NULL列,我将它们填满,现在我再次遇到错误的请求。

更新3

我明白了。我在数据库中有两个主键。当我调用UpdateAsync时,我只在对象中传递了一个键。当我通过两个键时,它起作用了。

Customer customer = new Customer
            {
                Id="10k", // first primary key
                CustomerId=12, // second primary key
                FirstName = FirstNamelbl.Text.ToString(),
                LastName = LastNamelbl.Text.ToString(),
                DOB = doblbl.Date,
                Email = Emaillbl.Text.ToString(),
                Sex = GenderGroup.SelectedItem.ToString()
            };
            // save customer input 
            await manager.UpdateCustomerRecordAsync(customer);

经理

public async Task UpdateCustomerRecordAsync(Customer customer)
        {
            try
            {
                await customerTable.UpdateAsync(customer);
            }
            catch (MobileServiceInvalidOperationException msioe)
            {
                Debug.WriteLine("Invalid sync operation: {0}", new[] { msioe.Message });

            }
            catch (Exception e)
            {
                Debug.WriteLine("Sync error: {0}", new[] { e.Message });
            }
        }