Avinash
Avinash

Reputation: 633

Calling a web service in windows phone 7 in MVVM architecture

I am calling a web service in Windows Phone 7.

I have added a service reference to a web service (.asmx Service) with the Refrence name RS. Then i am calling Service Like below:

Class AModel
{
     public void CreateT()
        {
           RS.RSSoapClient objRS = new RSRSSoapClient();
            objRS.Completed += new EventHandler<RS.CompletedEventArgs>(objRS_Completed);
            objRSAsync();
        }

    private void objRS_Completed(object sender, EventCompletedEventArgs e)
        {
             string str = e.Result;
             responseEventArgs = new ResponseEventArgs();
                responseEventArgs.response = e.Result;                
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(responseEventHandler, responseEventArgs);
        } 
}

Class BViewModel
{
       public void CreateT()
        {
            AModel objAModel = new AModel();
            objAModel.CreateT();
            objAModel .responseEventHandler += new ResponseEventHandler(objAModel_responseEventHandler);
        }

      private void objAModel_responseEventHandler(ResponseEventArgs e)
   {
     //doing some thing
    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(responseEventHandler, responseEventArgs);
  }
}

Here my Main problem is: Here i want to use MVVM architecture, So i am calling the Service in Model(Class AModel) Layer here i am invoking a event to notify the ViewModel(BViewModel) and Invoking same event in ViewModel to notify the View(.xaml page). Because of these events My app performance is degraded (time taken to bind the response is heavy). So please guide if make any thing wrong in implementing the MVVM architecture.

Thanks in advance.

Upvotes: 1

Views: 408

Answers (1)

Derek Beattie
Derek Beattie

Reputation: 9478

Let your ViewModel do the controlling. Put the calling of the web service in a service object, IMyService and have it return Dto(s). From the ViewModel call myService.GetThings(); then do with the results what is required. If you need to map, display or persist them.

Upvotes: 2

Related Questions