我正在尝试Azure Mobile应用和最近发布的SDK https://azure.microsoft.com/en-us/blog/azure-mobile-apps-november-2015-update/
我创建了该服务,并且启动器Todo应用程序运行正常。然后我添加了facebook身份验证,这也有效。我还想从服务中获得一些额外的FB信息,所以基于github上的解决方案和示例应用程序,我添加了一个新的api
服务器端代码
public class AuthenticationController : ApiController
{
[Authorize]
public async Task<JObject> GetIdentity()
{
FacebookCredentials fb = await this.User.GetAppServiceIdentityAsync<FacebookCredentials>(this.Request);
var result = new JObject();
if (fb != null)
{
var accessToken = fb.AccessToken;
result.Add("facebook", await GetProviderInfo("https://graph.facebook.com/me?access_token=" + accessToken));
}
return result;
}
private async Task<JToken> GetProviderInfo(string url)
{
var c = new HttpClient();
var resp = await c.GetAsync(url);
resp.EnsureSuccessStatusCode();
return JToken.Parse(await resp.Content.ReadAsStringAsync());
}
}
Android项目中的客户端代码
var user = await TodoItemManager.Instance.ClientInstance.LoginAsync(Forms.Context, MobileServiceAuthenticationProvider.Facebook);
var info = await TodoItemManager.Instance.ClientInstance.InvokeApiAsync("GetIdentity", null, HttpMethod.Get, null);
LoginAsync成功,我获得UserId和Token,但InvokeApiAsync失败并出现以下异常
Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<ThrowInvalidResponse>d__18.MoveNext () [0x0022f] in <filename unknown>:0
--- End of stack trace from previous location where exception was thrown ---
11-26 19:09:10.897 I/mono-stdout( 3514): at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<ThrowInvalidResponse>d__18.MoveNext () [0x0022f] in <filename unknown>:0
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
11-26 19:09:10.898 I/mono-stdout( 3514): --- End of stack trace from previous location where exception was thrown ---
11-26 19:09:10.898 I/mono-stdout( 3514): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
11-26 19:09:10.899 I/mono-stdout( 3514): at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
11-26 19:09:10.900 I/mono-stdout( 3514): at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:124
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient+<SendRequestAsync>d__1d.MoveNext () [0x0010d] in <filename unknown>:0
我错过了什么或做错了什么? 提前谢谢..
答案 0 :(得分:0)
I had a similar error in my project, using the new Azure App Service sample projects. I was simply trying to retrieve data from an Azure db using my own model classes, not doing authentication like you.
Here's the error:
Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Turns out, in my mobile server project, I had a model defined as CorporateEvent
, and in my client project, I had the same model defined as CorporateEventModel
. Once I renamed the model in my client project to CorporateEvent
, the error went away and I was able to access the database.
Hope that helps.