Reputation: 147
I have a self hosting WCF application with a java client. I have a WPF application which imlements the class
namespace WcfServiceLibrary6
{
class Products
{
public string ProductID { get; set; }
public string SerialNumber { get; set; }
public string RangeOfProducts { get; set; }
public string ProductDesc { get; set; }
public string UnitPrice { get; set; }
public string Discontinued { get; set; }
public string Image { get; set; }
// public Bitmap Bimage = new Bitmap(50, 50);
public System.Collections.IDictionary AttributeDictionary = new Dictionary<string, string>();
}
}
The data is stored as a list(the wpf application(C#) accesses a database)
Now I would like to bind this list to a data contract in wcf so it can send the information to the java client. How do I go about it. The rest of the application works perfectly. I just need to assign the list values(wpf: List productList = new List();) to the members of the data contract.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using WpfApplication24;
namespace WcfServiceLibrary6
{
// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in App.config.
[ServiceContract]
public interface IService1
{
[OperationContract]
Product getChars(int barid);
}
// Use a data contract as illustrated in the sample below to add composite types to service operations
[DataContract]
public class Product
{
private string m_ProductID;
private string m_SerialNumber;
private string m_RangeOfProducts;
private string m_ProductDesc;
private int m_UnitPrice;
private string m_Discontinued;
[DataMember]
public string ProductID
{
get { return m_ProductID; }
set { m_ProductID = value; }
}
[DataMember]
public string SerialNumber
{
get { return m_SerialNumber; }
set { m_SerialNumber = value; }
}
[DataMember]
public string RangeOfProducts
{
get { return m_RangeOfProducts; }
set { m_RangeOfProducts = value; }
}
[DataMember]
public string ProductDesc
{
get { return m_ProductDesc; }
set { m_ProductDesc = value; }
}
[DataMember]
public int UnitPrice
{
get { return m_UnitPrice; }
set { m_UnitPrice = value; }
}
[DataMember]
public string Discontinued
{
get { return m_Discontinued; }
set { m_Discontinued = value; }
}
}
}
Upvotes: 0
Views: 591
Reputation: 147
For anyone who needs help with hosting a wcf service, I found this website very useful : wcfguidanceforwpf.codeplex.com
Upvotes: 2
Reputation: 291
Add method with OnSerializing Attribute:
[OnSerializing()]
public void fun()
{
}
Where Product properties can be populated from the list.
Upvotes: 0