Azure 移动服务 UpdateAsync 给我 404 错误
Azure mobile services UpdateAsync gives me 404 error
我正在处理 xamarin 表单并使用 azure 移动服务。当我尝试更新记录时,UpdateAsync 不起作用并给我一个 404 错误。
调试时我注意到调试器中有以下行:
<b> Requested URL: </b>/tables/Customer/10k<br><br>
10k 是 ID。
当我将 postman 与上面的 link 一起使用时,它返回相同的 404 错误。但是,如果我使用 link /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. 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> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0
</font>
</body>
</html>
<!--
[HttpException]: The controller for path '/tables/Customer/10k' 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 <customErrors mode="Off"/>. Consider using <customErrors mode="On"/> or <customErrors mode="RemoteOnly"/> in production environments.-->
我找到了解决方案,但 运行 遇到了另一个问题。
我在客户控制器上面有这条线
[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 }
);
但是现在当我从客户端更新时它给我错误的请求错误。
更新
我修复了错误的请求错误。
在我的后端客户 class 我有日期时间?在我的客户 class 中,我有日期时间 .. 我删除了? .
现在我收到内部服务器错误。
更新 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 });
}
}
我正在处理 xamarin 表单并使用 azure 移动服务。当我尝试更新记录时,UpdateAsync 不起作用并给我一个 404 错误。
调试时我注意到调试器中有以下行:
<b> Requested URL: </b>/tables/Customer/10k<br><br>
10k 是 ID。
当我将 postman 与上面的 link 一起使用时,它返回相同的 404 错误。但是,如果我使用 link /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. 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> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0
</font>
</body>
</html>
<!--
[HttpException]: The controller for path '/tables/Customer/10k' 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 <customErrors mode="Off"/>. Consider using <customErrors mode="On"/> or <customErrors mode="RemoteOnly"/> in production environments.-->
我找到了解决方案,但 运行 遇到了另一个问题。
我在客户控制器上面有这条线
[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 }
);
但是现在当我从客户端更新时它给我错误的请求错误。
更新
我修复了错误的请求错误。 在我的后端客户 class 我有日期时间?在我的客户 class 中,我有日期时间 .. 我删除了? .
现在我收到内部服务器错误。
更新 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 });
}
}