c# - Mobile Service Client throws exception when response is not found -
i trying port application azure mobile service azure web app. (the mobile service working). have added microsoft account authentication web-app, , web app api has mobileappcontroller attribute. have universal windows app front end calls api. app first checks if player in database, if not not found response. if call method using following code mobileserviceclient exception.
private async task<httpresponsemessage> getazmasyncp(string apiext, idictionary<string,string> param ) { string myuri = string.format("{0}{1}", urlbase, apiext);
//client mobileserviceclient correctly logged in //i not response 404 not found, exception "the request not completed, not found" var response = await client.invokeapiasync(myuri, system.net.http.httpmethod.get, param); return response; } if call api httpclient , add own headers, mobile client supposed me, response requested. here code:
private async static task<httpresponsemessage> getazasync(string apiext) { string completeurl = string.format("{0}{1}", urlbase, apiext); // call out az using (var http = new httpclient()) { // http.baseaddress = new uri(completeurl); httprequestmessage rq = new httprequestmessage() { requesturi = new uri(completeurl), method = httpmethod.get }; addauthheader(rq); var response = await http.sendasync(rq); return response; } } private static void addauthheader(httprequestmessage rq) { mobileserviceuser user = app.client.currentuser; rq.headers.add("x-zumo-features", "at,qs"); rq.headers.add("x-zumo-installation-id", "ff90f37e-0c03-4c52-a343-af711752e383"); rq.headers.add("x-zumo-auth", user.mobileserviceauthenticationtoken); rq.headers.add("accept", "application/json"); rq.headers.add("user-agent", "zumo/2.1"); rq.headers.add("user-agent", "(lang = managed; os = windows store; os_version = --; arch = x86; version = 2.1.40707.0)"); rq.headers.add("x-zumo-version", "zumo/2.1(lang = managed; os = windows store; os_version = --; arch = x86; version = 2.1.40707.0)"); rq.headers.add("zumo-api-version", "2.0.0"); }
you can try out live (and buggy).
https://gamenote2.azurewebsites.net/api/players?displayname=paul goldschmidt&teamid=arizona-diamondbacks should give 404, https://gamenote2.azurewebsites.net/api/players?displayname=chase utley&teamid=los-angeles-dodgers should give chase utley object. (you asked log microsoft account).
so questions: 1. can fix mobileclient call response instead of execption 2. there reason me spending time on this.
if examine exception, note status code in there - it's in property not serialized. surround invokeapiasync() call try/catch , test statuscode. should lot easier writing own http client code same purpose.
specifically, mobileserviceinvalidoperationexception
contains httpresponse of failed request, can check exception.response.statuscode
value.
Comments
Post a Comment