Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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. </p> <p>1) The main problem I see in your project is you have two definitions of <code>Student</code> class. You can easily merge them into a single definition. (I will just show you how...)</p> <p>2) It is very unclear whether you want your <code>WPF</code> client to save data to a <code>Data Source</code> (<code>XML</code>?) or your <code>Web Service</code> should do it. And if the <code>WPF</code> client is supposed to save the <code>Student</code>s then what is the <code>Web Service</code> for?</p> <p>3) You don't have a <code>ViewModel</code> defined anywhere for the <code>Student</code> class which in this case is <code>Model</code>.</p> <p>I have created an example with 3 projects.</p> <p>1) <code>WebService</code> - A WCF Service Project</p> <p>2) <code>StudentLib</code> - A Class Library Project (where <code>Student</code> class is defined)</p> <p>3) <code>DesktopClient</code> - A WPF Application Project</p> <p>Here is the source code :</p> <p><code>WebService.IStudentService.cs</code></p> <pre><code>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); } } </code></pre> <p><code>WebService.StudentService.cs</code></p> <pre><code>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 } } } </code></pre> <p><code>WebService's Web.Config</code></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;compilation debug="true" targetFramework="4.0" /&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;bindings /&gt; &lt;client /&gt; &lt;services&gt; &lt;service name="WebService.StudentService" behaviorConfiguration="metaDataBehavior"&gt; &lt;endpoint address="basic" binding="basicHttpBinding" contract="WebService.IStudentService" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="metaDataBehavior"&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt; &lt;/system.serviceModel&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"/&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p><code>StudentLib.Student.cs</code></p> <pre><code>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; } } } </code></pre> <p><code>DesktopClient.StudentViewModel.cs</code></p> <pre><code>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; } } } } </code></pre> <p><code>DesktopClient.MainWindow.xaml</code></p> <pre><code>&lt;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"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;TextBlock Grid.Column="0" Grid.Row="0"&gt;Name :&lt;/TextBlock&gt; &lt;TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Name}"&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Column="0" Grid.Row="1"&gt;Score :&lt;/TextBlock&gt; &lt;TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Score}"&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Column="0" Grid.Row="2"&gt;Time Added :&lt;/TextBlock&gt; &lt;TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding TimeAdded}"&gt;&lt;/TextBlock&gt; &lt;TextBlock Grid.Column="0" Grid.Row="3"&gt;Comment :&lt;/TextBlock&gt; &lt;TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding Comment}"&gt;&lt;/TextBlock&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p><code>DesktopClient.MainWindow.cs</code></p> <pre><code>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 { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; 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" }); } } } </code></pre> <p>Here all the above mentioned problems are resolved :</p> <p>1) The <code>Student</code> class is defined in a common assembly (<code>StudentLib</code>) referenced by both <code>WebService</code> project and <code>DesktopClient</code> project. So, while adding a <code>Service Reference</code>, that class is reused by the code generator.</p> <p>2) I recommend all the storage related operations be in the <code>Web Service</code> and the <code>Client</code> app should just use <code>Web Service</code> to store data.</p> <p>3) <code>StudentViewModel</code> class is used instead of <code>Student</code> class to display data in <code>MainWindow</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload