2017-09-27 45 views
1

我是Windows應用程序開發新手。我試圖消耗與移動服務客戶端服務API與下面的代碼如何使用Xamarin表單中的applicationKey使用service api?

MobileServiceClient mSClient; 
mSClient = new MobileServiceClient("https://*******.azure-mobile.net/", "UFakeKkrayuAeVnosdfghrwvnhdfVAcjYziYFSFHUV89"); 

Dictionary<string, string> userobj = new Dictionary<string, string>(); 
userobj.Add("UserName", "username"); 
userobj.Add("Password", "password"); 
userobj.Add("DeviceUID", "010092780200134E0300215F0400CC37050083D807006B9B080066010900267F"); 
userobj.Add("DeviceToken", "device_123"); 
userobj.Add("OSVersion", "WindowsPhone"); 
userobj.Add("AppVersion", "2.0"); 
userobj.Add("DeviceModel", "Windows phone"); 
userobj.Add("DeviceTypeID", "1"); 
userobj.Add("DeviceAlertsOn","true");  

var responce = mSClient.InvokeApiAsync("user/loguserin", HttpMethod.Post, userobj); 

塊,但我沒有得到正確的響應:

enter image description here

誰能幫助我?

謝謝, Srinivas。

+0

你調用一個異步方法 – Jason

+0

添加到傑森和壽司時需要用到等待,當你不不用等待,你的響應將包含任務對象。您可以訪問來自'responce'對象的狀態和錯誤。你稍後可以'等待響應'來運行它。這對更多的調試很有幫助 –

+0

感謝Neville,你能否給我一些合適的代碼塊來得到回覆 –

回答

1

你是不是等待異步方法,因此你看到的WaitingForActivition狀態:

var responce= await mSClient.InvokeApiAsync(....... 
+0

謝謝你的回覆,我現在回答你的回答我收到以下異常mscorlib.ni.dll中發生類型'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException'的異常,但沒有在用戶代碼 –

+0

@srinivaschalla中處理您需要查看異常('MobileServiceInvalidO perationException')的'Value'和'Response'屬性以確定服務器拒絕您的調用的原因。 '提供特定於移動服務的無效操作的其他詳細信息。 'https://docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.mobileservices.mobileserviceinvalidoperationexception?view=azure-dotnet – SushiHangover

+0

獲取響應爲{StatusCode:400,ReasonPhrase:'Bad Request',版本:1.1,內容:System.Net.Http.StreamContent,集管: { 服務器:IIS/8.0 的Set-Cookie:ARRAffinity = 05b093af5f4e7c6d198da2b2771de80c714f0499531fcab7ac6cc84e48dfeafc;路徑= /;的HttpOnly;域= chiefservices.azure-mobile.net 日期:2017年3月27日星期三05:08:30 GMT X-Powered-by-ASP.NET- Content-Length:81 Content-Type:application/json; charset = utf-8 }}和Value as null –

相關問題