2011-11-26 8 views
0

MVVM 라이트 패턴을 사용하여 WPF 프런트 엔드를 만듭니다. 이 프런트 엔드는 웹 서버를 호출하여 응용 프로그램 서버에서 데이터를 검색합니다. 응용 프로그램 서버는 .dll을 통해 웹 메서드를 제공하는 독점 공급 업체 응용 프로그램 서버입니다.MVVM Light를 공급 업체의 Webservice와 함께 사용

서버에서 결과를 얻으려면 서버에서 클라이언트 세션을 가져와야합니다. 문제는 그 I는 서버에 연결이 내 모델을 호출 할 때, 나는 다음과 같은 오류 얻을 : 나는 시스템은 계속하고 생산

cashaccount.getConnection(); 

줄을 촬영하면

'The invocation of the constructor on type [APP].ViewModel.ViewModelLocator' that matches the specified binding constraints threw an exception.' Line number '12' and line position '10'. 

을 WPF Toolkit의 Data Grid가있는 WPF 창

MainWindow.xaml

<Window x:Class="CreditSuisse.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" 
     mc:Ignorable="d" 
     Height="301" 
     Width="520" 
     Title="MVVM Light Application" 
     DataContext="{Binding Main, Source={StaticResource Locator}}"> 

    <Window.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="Skins/MainSkin.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Window.Resources> 


    <dg:DataGrid ItemsSource="{Binding Path=CashAccount}" 
       Margin="5" AutoGenerateColumns="False"> 
     <dg:DataGrid.Columns> 
      <dg:DataGridTextColumn Binding="{Binding AcctCd}" Header="Account Code" /> 
      <dg:DataGridTextColumn Binding="{Binding AcctCd}" Header="Security Name" /> 
      <dg:DataGridTextColumn Binding="{Binding QtySod}" Header="Quantity Start of Day" /> 
      <dg:DataGridTextColumn Binding="{Binding QtySod}" Header="Cash Delta (Price Delta)" /> 
      <dg:DataGridTextColumn Binding="{Binding QtySod}" Header="Action" /> 
     </dg:DataGrid.Columns> 
    </dg:DataGrid> 




</Window> 

ViewModel.cs

public MainViewModel() 
    { 
     if (IsInDesignMode) 
     { 
      // Code runs in Blend --> create design time data. 
     } 
     else 
     { 
      logger.Info("----- Start -----"); 
      cashaccount.getConnection(); 
     } 
    } 

나는 간결하게하기 위해 생략했습니다.

는 여기가 서비스 에이전트가 더 나은 방법이 될 것입니다 있는지 확인하기 위해 찾고

CashAccount.cs

public class CashAccount : xx.xx.Position 
    { 
     private bool cashChanged=false; 
     private string secName = null; 
     private xxx.Wsi.ClientSession privateSession; 
     private static Logger logger = LogManager.GetCurrentClassLogger(); 
     public bool didCashChange 
     { 
     get 
     { 
      return cashChanged; 
     } 
     set 
     { 
      this.cashChanged = value; 
     } 
    } 

    public void getConnection() 
    { 
     try 
     { 
      app.Helper.Session session = new Session(); 

      privateSession = session.getSession(); 
         } 
     catch (TransportException e) 
     { 
      Console.WriteLine("Error communicating with server: " + e.Message); 
      logger.Info("Couldn't log into xxx..."); 
      logger.Error(e.Message); 
     }   
     { 
     } 
    } 
    } 
} 

모델에게 있습니다. 누구든지 아이디어가 있다면 그것을 고맙게 생각할 것입니다.

답변

1

이 예외는 ViewModel이 (리소스 섹션을 통해) XAML 파서에 의해 만들어지고 작성 중에 예외가 발생할 때 발생합니다. 여기서 볼 수있는 것은 그 예외의 결과 일뿐입니다. 즉 ViewModel을 만들지 못했습니다.

어떻게되는지 알아 보려면 ViewModel 생성자에 중단 점을 배치하고 디버그 모드로 앱을 실행하십시오. 내부 코드가 충돌하고 있음을 알 수 있습니다.

일반적으로 말해서 VM을 구축하는 동안 웹 서비스에 연결하지 않는 것이 좋습니다. 이렇게하면 응용 프로그램의 시작 속도가 느려지고 첫 번째 창 모양이 지연됩니다. 차라리 VM을 생성하고 창을 "기다려주십시오"메시지와 함께 표시 한 다음 웹 서비스에 대한 연결 만 (예 : Window의 "로드 됨"이벤트에 의해 트리거 됨) 발생시키는 것이 좋습니다.

건배, 로랑

0

글쎄, 내 특정한 경우에 I가 등록 된 클래스의 생성자는 개인이었다. 예외가 명시된 것보다 구체적이거나 적어도 올바른 내부 예외가 있었으면 좋겠다. C#/CLR 이슈.

관련 문제