Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:49:16+00:00 2026-05-15T14:49:16+00:00

I’m going to do a wpf application using MVVM(It based on http://www.codeproject.com/KB/WPF/MVVMQuickTutorial.aspx ). This

  • 0

I’m going to do a wpf application using MVVM(It based on http://www.codeproject.com/KB/WPF/MVVMQuickTutorial.aspx
).

This application will be connecting with webservice one per month.

On webservice I have contract

public class Student
{
        public string Name {get; set;}
        public int Score {get; set;}
        public DateTime TimeAdded {get; set;}
        public string Comment {get; set;}
}

In WPF application Adding, and removing students will be saving to xml file.

So at wpf application Student would be something like :

public class Student
{
    public string Name {get; set;}
    public int Score {get; set;}
    public DateTime TimeAdded {get; set;}
    public string Comment {get; set;}

    public Student(string Name, int Score,
        DateTime TimeAdded, string Comment) {
        this.Name = Name;
        this.Score = Score;
        this.TimeAdded = TimeAdded;
        this.Comment = Comment;
    }
}

public class StudentsModel: ObservableCollection<Student>
{
    private static object _threadLock = new Object();
    private static StudentsModel current = null;

    public static StudentsModel Current {
        get {
            lock (_threadLock)
            if (current == null)
                current = new StudentsModel();

            return current;
        }
    }

    private StudentsModel() 
    {

        // Getting student s from xml
        }
    }

    public void AddAStudent(String Name,
        int Score, DateTime TimeAdded, string Comment) {
        Student aNewStudent = new Student(Name, Score,
            TimeAdded, Comment);
        Add(aNewStudent);
    }
}

How connect this two classes ?

The worst think I guess is that contract Student from webservice would be use in this wpf application to get students from xml, in other application collection of studetns would be getting from database.

I’m newbie in design patterns so it is very hard for me :/

Example: I click AddUser, and in application A it calls webservice method which adding user to database, in application B it adds user to XML file, and In application.
Base class are contracts at webservice.

Next explanation:

First application uses webservice to save data at database. Second application never save data in xmls and one perm month send this xmls to webservice and convert their to intances of students and save it at database

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:49:17+00:00Added an answer on May 15, 2026 at 2:49 pm

    It is very unclear from your question what the actual problem is. But, I guess I could address a few and show you a way to solve them.

    1) The main problem I see in your project is you have two definitions of Student class. You can easily merge them into a single definition. (I will just show you how…)

    2) It is very unclear whether you want your WPF client to save data to a Data Source (XML?) or your Web Service should do it. And if the WPF client is supposed to save the Students then what is the Web Service for?

    3) You don’t have a ViewModel defined anywhere for the Student class which in this case is Model.

    I have created an example with 3 projects.

    1) WebService – A WCF Service Project

    2) StudentLib – A Class Library Project (where Student class is defined)

    3) DesktopClient – A WPF Application Project

    Here is the source code :

    WebService.IStudentService.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using StudentLib;
    
    namespace WebService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IStudentService" in both code and config file together.
        [ServiceContract]
        public interface IStudentService
        {
            [OperationContract]
            StudentLib.Student GetStudentById(Int32 id);
    
            [OperationContract]
            void AddStudent(StudentLib.Student student);
        }
    }
    

    WebService.StudentService.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using StudentLib;
    
    namespace WebService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "StudentService" in code, svc and config file together.
        public class StudentService : IStudentService
        {
            public StudentLib.Student GetStudentById(int id)
            {
                return new StudentLib.Student() { Name = "John Doe", Score = 80, TimeAdded = DateTime.Now, Comment = "Average" };
            }
    
            public void AddStudent(StudentLib.Student student)
            {
                // Code to add student
            }
        }
    }
    

    WebService's Web.Config

    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <bindings />
        <client />
        <services>
          <service name="WebService.StudentService" behaviorConfiguration="metaDataBehavior">
            <endpoint address="basic" binding="basicHttpBinding" contract="WebService.IStudentService" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="metaDataBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    </configuration>
    

    StudentLib.Student.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Runtime.Serialization;
    
    namespace StudentLib
    {
        [DataContract]
        public class Student
        {
            [DataMember]
            public String Name { get; set; }
    
            [DataMember]
            public Int32 Score { get; set; }
    
            [DataMember]
            public DateTime TimeAdded { get; set; }
    
            [DataMember]
            public String Comment { get; set; }
        }
    }
    

    DesktopClient.StudentViewModel.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace DesktopClient
    {
        class StudentViewModel
        {
            protected StudentLib.Student Student { get; set; }
    
            public StudentViewModel(StudentLib.Student student)
            {
                this.Student = student;
            }
    
            public String Name { get { return Student.Name; } }
            public Int32 Score { get { return Student.Score; } }
            public DateTime TimeAdded { get { return Student.TimeAdded; } }
            public String Comment { get { return Student.Comment; } }
        }
    }
    

    DesktopClient.MainWindow.xaml

    <Window x:Class="DesktopClient.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow"
            Width="400"
            Height="300"
            Loaded="Window_Loaded">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <TextBlock Grid.Column="0"
                       Grid.Row="0">Name :</TextBlock>
            <TextBlock Grid.Column="1"
                       Grid.Row="0"
                       Text="{Binding Name}"></TextBlock>
            <TextBlock Grid.Column="0"
                       Grid.Row="1">Score :</TextBlock>
            <TextBlock Grid.Column="1"
                       Grid.Row="1"
                       Text="{Binding Score}"></TextBlock>
            <TextBlock Grid.Column="0"
                       Grid.Row="2">Time Added :</TextBlock>
            <TextBlock Grid.Column="1"
                       Grid.Row="2"
                       Text="{Binding TimeAdded}"></TextBlock>
            <TextBlock Grid.Column="0"
                       Grid.Row="3">Comment :</TextBlock>
            <TextBlock Grid.Column="1"
                       Grid.Row="3"
                       Text="{Binding Comment}"></TextBlock>
        </Grid>
    </Window>
    

    DesktopClient.MainWindow.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using DesktopClient.StudentService;
    using StudentLib;
    
    namespace DesktopClient
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                IStudentService client = new StudentServiceClient();
    
                Student student = client.GetStudentById(1);
                DataContext = new StudentViewModel(student);
    
                client.AddStudent(new StudentLib.Student() { Name = "Jane Doe", Score = 70, TimeAdded = DateTime.Now, Comment = "Average" });
            }
        }
    }
    

    Here all the above mentioned problems are resolved :

    1) The Student class is defined in a common assembly (StudentLib) referenced by both WebService project and DesktopClient project. So, while adding a Service Reference, that class is reused by the code generator.

    2) I recommend all the storage related operations be in the Web Service and the Client app should just use Web Service to store data.

    3) StudentViewModel class is used instead of Student class to display data in MainWindow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.