2017-08-17 8 views
0

これは初めての投稿です。私はすべての関連情報を取得しようとします。 BS CapstoneクラスのUWPを開発しています。私は、ユーザーにユーザー名とパスワードを入力してログインさせるか、ユーザー名とパスワードを入力してログインできるようにするメインページを用意しています。そこにはいくつかの例外がありますユーザーが登録されていない場合は、登録する必要があることを知らせるダイアログが表示されます。 問題は、登録されていないことがわかっているユーザー名とパスワードを入力するとアプリがクラッシュすることです。 私はVS 2015とAzure SQLデータベースを使用しています。私は何が間違っている唯一の手がかりは、出力は、次のメッセージを示しています。 例外がスローされた: 'System.Net.Http.HttpRequestException' をmscorlib.ni.dllにユーザ名とパスワードを入力するとUWPがクラッシュする

また、私は最後に

public static MobileServiceClient MobileService = new 
MobileServiceClient("http://tale-server1.database.windows.net"); 

としてApp.Xaml.csタブでの接続文字列を持っている、しようとしたとき新しいユーザーを登録するには、

catch (Exception em) 
     { 
      var dialog = new MessageDialog("An Error Occured: " + 
em.Message); 
      await dialog.ShowAsync(); 
     } 

私のメインページのコードは以下のとおりです。

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Runtime.InteropServices.WindowsRuntime; 
using Windows.Foundation; 
using Windows.Foundation.Collections; 
using Windows.UI.Xaml; 
using Windows.UI.Xaml.Controls; 
using Windows.UI.Xaml.Controls.Primitives; 
using Windows.UI.Xaml.Data; 
using Windows.UI.Xaml.Input; 
using Windows.UI.Xaml.Media; 
using Windows.UI.Xaml.Navigation; 
using Microsoft.WindowsAzure.MobileServices; 
using System.Threading.Tasks; 
using Windows.UI.Popups; 
using Windows.Storage; 
using System.Net.Http; 
using Newtonsoft.Json; 
using SQLite; 
using SQLite.Net; 
using SQLite.Net.Async; 
using Microsoft.WindowsAzure.MobileServices.Sync; 
using Microsoft.WindowsAzure.MobileServices.SQLiteStore; 
using SQLitePCL; 


// The Blank Page item template is documented at 
http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 

namespace TALE_Capstone 
{ 
/// <summary> 
/// An empty page that can be used on its own or navigated to within a 
Frame. 
/// </summary> 
public sealed partial class MainPage : Page 
{ 
    public MainPage() 
    { 
     this.InitializeComponent(); 
    } 

    public int IsAuth { get; set; } 

    //[DataTable("User_Cred")] 
    public class User_Cred 
    { 
     public string id { get; set; } 
     public string userName { get; set; } 
     public string Password { get; set; } 

    } 

    private IMobileServiceSyncTable<User_Cred> todoGetTable = 
App.MobileService.GetSyncTable<User_Cred>(); 



    private async Task InitLocalStoreAsync() 
    { 
     if (!App.MobileService.SyncContext.IsInitialized) 
     { 
      var store = new MobileServiceSQLiteStore("Tale-DB"); 
      store.DefineTable<User_Cred>(); 
      await App.MobileService.SyncContext.InitializeAsync(store); 
     } 
     await SyncAsync(); 
    } 

    private async Task SyncAsync() 
    { 
     await App.MobileService.SyncContext.PushAsync(); 
     await todoGetTable.PullAsync("User_Cred", 
todoGetTable.CreateQuery()); 
    } 



    async public void submitAuthBtn_Click(object sender, RoutedEventArgs e) 
    { 
     await InitLocalStoreAsync(); 

     GetAuthentication(); 

    } 

    async public void GetAuthentication() 
    { 
     try 
     { 

      //IMobileServiceTable<User_Cred> todoTable = App.MobileService.GetTable<User_Cred>(); 

      List<User_Cred> items = await todoGetTable 
       .Where(User_Cred => User_Cred.userName == UserNameEnter.Text) 
       .ToListAsync(); 

      IsAuth = items.Count(); 

      // Return a List UI control value back to the form 

      foreach (var value in items) 
      { 
       var dialog = new MessageDialog("Welcome Back " + value.userName); 
       await dialog.ShowAsync(); 
      } 


      if (IsAuth > 0) 
      { 
       var dialog = new MessageDialog("You are Authenticated"); 
       await dialog.ShowAsync(); 

      } 
      else 
      { 
       var dialog = new MessageDialog(" Account Does Not Exist, please Register to get Started."); 
       await dialog.ShowAsync(); 
      } 
     } 
     catch (Exception em) 
     { 
      var dialog = new MessageDialog("An Error Occured: " + em.Message); 
      await dialog.ShowAsync(); 
     } 
    } 

    async private void submitAuthBtn_Copy_Click(object sender, RoutedEventArgs e) 
    { 
     try 
     { 
      User_Cred itemReg = new User_Cred 
      { 
       userName = UserNameEnter.Text, 
       Password = PWEnter.Text 
      }; 
      await App.MobileService.GetTable<User_Cred>().InsertAsync(itemReg); 
      var dialog = new MessageDialog("Thank you for Registering! Lets begin"); 
      await dialog.ShowAsync(); 
     } 
     catch (Exception em) 
     { 
      var dialog = new MessageDialog("An Error Occured: " + em.Message); 
      await dialog.ShowAsync(); 
     } 
    } 



} 
} 

任意の助けいただければ幸いです!

コンラッド

答えて

0

はあなたの説明によると、私はあなたがデータを格納するためのAzureモバイルアプリのバックエンドとAzureのSQLデータベースを使用してUWPアプリを接続していることを想定しました。次のように私の知る限り、MobileServiceClientの初期設定は次のようになります。

MobileServiceClient MobileService = new MobileServiceClient("https://{your-appname}.azurewebsites.net"); 

私はあなたがこのtutorialに従うと、この問題をチェックするためにsample client projectをダウンロードすることができ推薦します。また、fiddlerを活用し、uupアプリをazureモバイルアプリに接続して詳細なエラーメッセージを受け取ったときにネットワークトレースを収集すると、この問題を絞り込むことができます。または、この問題を見つけるための詳細なエラーで質問を更新できます。

+0

私は実際に参照がないことを知りました。しかし、努力をありがとう:) – CHernandez

関連する問題