.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> WCF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Generic Dal using WCF - Part 4

Posted By:Mahadesh Mahalingappa       Posted Date: September 20, 2011    Points: 200    Category: WCF    URL: http://www.dotnetspark.com  

In this article we would create our WCF Business Layer Methods.
 

Generic Dal using WCF - Part 4:
 

Other articles of this series can be found here

Generic Dal using WCF

Generic Dal using WCF: Part 2

Generic Dal using WCF - Part 3


 In this article we would create our WCF Business Layer Methods .
 

 
 
First step I always do is clear off all the Default Code that is generated by th WCF Service .
 
Add  the Generic Dal Reference to the wcf project .
 
 
Also add the System.Data.Entity Reference as shown below :


 
Created the Service Methods as shown below :
  

public class Service1 : IService1
{
    public void Add(TEntity entity)
    {
        PublishingCompanyEntities context = new PublishingCompanyEntities();
        ObjectSet _ObjectSet = context.CreateObjectSet();
        _ObjectSet.AddObject(entity);
    }

    public TEntity Get(TEntity entity)
    {
        PublishingCompanyEntities context = new PublishingCompanyEntities();
        ObjectSet _ObjectSet = context.CreateObjectSet();
        TEntity company = _ObjectSet.First();
        return company;
    }
}


  
The Service Contract is shown below :
  

[ServiceContract]
public interface IService1
{
    [OperationContract]
    void Add(TEntity entity);

    [OperationContract]
    TEntity Get(TEntity entity);

}


 Creating the Client :





The Client code is shown below :
  

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using Client.DataServiceReference;
 using GenericDal;
  
 namespace Client
 {
   class Program
   {
   static void Main(string[] args)
   {
  
   Service1Client client = new Service1Client();
  
   GenericDal.TEntity entity = new GenericDal.Article();
  
  
   client.Get(entity);
   }
   }
 }

The Solution Builds Successfully .  Run the Client Project .
 
 

 
 
The Run fails and we get the following error when we debug .  There seems to be a error in the serialization in WCF .  


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend