Any tutorials for Data Access Layer in WCF Service Factory ?

Topics: July and December Releases Forum
Aug 2, 2007 at 6:52 AM
Hi All,

There were good webcasts on how to use the WCF Service Factory and creating Data Contracts, Message Contracts, Service Implementation. I couldnt find a good resource for starting the Data Access layer where I could connect to SQL Server 2005 and have Add/Delete/Update/Edit records for tables and also execute stored procedures from the WCF Service.

Any help is appreciated :)

Thanks,

Regards,
Chaks
Aug 2, 2007 at 7:04 AM
I just went through the Guidance Package help and it seems to be really good :)

Following the guide...will post here if I have any doubts...

Thanks

Regards,
Chaks
Aug 2, 2007 at 2:16 PM
Yes, the data access guidance is the place to look.

Also note that the next version of that guidance is going to be a separate factory: http://www.codeplex.com/repositoryfactory.

The issues and posts in there are a good place to take a quick glance at its current limitations.

Regards,
Freddy - www.gcm.com.ve
Aug 7, 2007 at 3:03 PM


FreddyRios wrote:
Yes, the data access guidance is the place to look.

Also note that the next version of that guidance is going to be a separate factory: http://www.codeplex.com/repositoryfactory.

The issues and posts in there are a good place to take a quick glance at its current limitations.

Regards,
Freddy - www.gcm.com.ve


I am currently starting my new work with the latest stable release of WCF Service Factory. I dont have time to wait for the upcoming release :(

It should be ok for me to go on right ?
Aug 8, 2007 at 3:53 PM
Edited Aug 8, 2007 at 3:54 PM
I just added a screencast on PnPGuidance that shows how to use the Data Access Guidance Package if you want to use it:

Create Data Access Layer Using Data Access Guidance Package Screencast

I would use the Data Access Guidance Package as part of the Service Factory right now as the RepositoryFactory is still too early to use in my opinion.

Regards,

Dave

____________________________

David Hayden
Microsoft MVP C#
Aug 8, 2007 at 4:05 PM


DavidHayden wrote:
I just added a screencast on PnPGuidance that shows how to use the Data Access Guidance Package if you want to use it:

Create Data Access Layer Using Data Access Guidance Package Screencast

I would use the Data Access Guidance Package as part of the Service Factory right now as the RepositoryFactory is still too early to use in my opinion.


Thanks Dave :)

Downloading it ! Thanks a lot !

Regards,
Chaks
Aug 9, 2007 at 11:19 AM
Dave, thanks for the screencast. It did give an insight on how to get started.

I am finding a bit difficult with the WCF Service Factory where Data Access Guidance Package is included by default. I am using the created project with all responsibilities by default.

So here is what I do.

1) I have my SQL Database and the necessary stored procedures already created in my local SQL Server 2005 Express Edition
2) I create the Database Connection
3) I then create the Business Entities
4) Create Data Repository Classes and map the stored procedures input/output parameters with Business Entities
5) Now I get a lot of classes (under DataAccess) and interfaces being implemented and I went through the Guidance Package Documentation to get to know each Interface

So now I move to my Service Implementation class and see that I am not able to connect to the repository.

I found that I had to manually add the DataAccess reference to accesss the repository classes.

Is this the way ? or am I doing something wrong ?

Here is the code of my Service Implementation

*********************************************************************************************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using EducatorService.ServiceContracts;
using EducatorService.DataAccess;
using EducatorService.BusinessEntities;

namespace EducatorService.ServiceImplementation
{
ServiceBehavior(Name = "Educator", Namespace = "http://EducatorService.ServiceContracts/2007/08")
public class Educator : IEducator
{
#region IEducator Members

public RegisterResponse AddTutor(RegisterTutor request)
{
TutorDetails tutDetails=new TutorDetails();
tutDetails.TutorID = request.Tutor.TutorId;
tutDetails.TutorName = request.Tutor.TutorName;
tutDetails.TutorContact = request.Tutor.TutorContact;

TutorDetailsRepository tut_repository = new TutorDetailsRepository("Educator");

tut_repository.Add(tutDetails);
}

#endregion
}
}
*********************************************************************************************************************************************************

I think the code is self explanatory :)

I would be happy if anyone could help me here.

Thanks,

Regards,
Chaks
Aug 9, 2007 at 3:00 PM
If you are using the solution structure as defined by the WCF Guidance Package, it is expected that you would access the data access layer from the business logic layer. You may notice in your solution that EducatorService.BusinessLogic already has a reference to EducatorService.DataAccess.

Hence you may have a class like TutorServices in the BLL:

public class TutorServices
{
    public void AddTutor(TutorDetails tutDetails)
    {
        TutorDetailsRepository tut_repository = new TutorDetailsRepository("Educator");
        tut_repository.Add(tutDetails);
    }
}

and then in your WCF Service Implementation you may have:

public RegisterResponse AddTutor(RegisterTutor request)
{
    TutorDetails tutDetails=new TutorDetails();
    tutDetails.TutorID = request.Tutor.TutorId;
    tutDetails.TutorName = request.Tutor.TutorName;
    tutDetails.TutorContact = request.Tutor.TutorContact;
 
    TutorServices services = new TutorServices();
    services.AddTutor(tutDetails);
 
    // ...
}

I have left off the validation and exception handling that you would want to do, but this gives you the overall idea. The reference implementation probably goes into this in more detail.

Regards,

Dave

_______________________________

David Hayden
Microsoft MVP C#
Aug 9, 2007 at 9:34 PM
Thanks Dave, that was of great help !

--------
Regards,
Chaks