Hi!
I'm working with a project there i have a WCF Library, Empty SharePoint project and i've added a Visual Web Part.
I got one TextBox_Search and some other textboxes like, TextBox_Name.
I want to search in my Database with my TextBox_Search and then display the name value from my Database in my TextBox_Name, Color, etc...
Here's some code i'm using:
WCF:
Service1.cs:
public Product GetProduct(int id)
{
using (var db = new AdventureWorks2008Entities())
{
var productEntitie = (from data in db.ProductEntities
where data.ProductID == id
select data).FirstOrDefault();
if (productEntitie != null)
return TranslateProductEntityToProduct(productEntitie);
else
throw new Exception("Invalid product id");
}
}
private Product TranslateProductEntityToProduct(ProductEntity productEntity)
{
var prod = new Product
{
ProductName = productEntity.Name,
ProductID = productEntity.ProductID,
ProductNumber = productEntity.ProductNumber,
ListPrice = productEntity.ListPrice,
Color = productEntity.Color
};
return prod;
}
IService.cs:
public interface IProductService
{
[OperationContract]
Product GetProduct(int id);
}
// Use a data contract as illustrated in the sample below to add composite types to service operations
[DataContract]
public class Product
{
[DataMember]
public int ProductID { get; set; }
[DataMember]
public string ProductNumber { get; set; }
[DataMember]
public decimal ListPrice { get; set; }
[DataMember]
public string ProductName { get; set; }
[DataMember]
public string Color { get; set; }
}
In my SharePoint project:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Search_Click(object sender, EventArgs e)
{
var srvRef = new ServiceReference1.Product();
//Here's my problem. When i type:
// TextBox_Search.Text = srvRef.ProductID.ToString(TextBox_Name.Text);
// I get value 0 in my TextBox_Search, not Name.
}
Thanks and hope to hear from you!
Kind regards,
Kristian.