darking050
darking050

Reputation: 637

WCF with AdventureWorks SQL Server database

I am testing the WCF facility with the AdventureWorks SQL Server database (The table name Person).

When testing it in the wcftestclient.exe, it gives red icon and says:

This Operation is not supported in the WCF test client because it uses type AdventureWorksDbWcf.Person

This is the service.svc.cs service class.

namespace AdventureWorksDbWcf
{   
    public class Service : IService
    {
        AW_DataClassesDataContext db = new AW_DataClassesDataContext();

        public Person GetOnePerson(int BusinessEntityID)
        {
            var _person = from one in db.Persons
                          select one;

            Person onlyOnly;

            return onlyOnly = _person.First<Person>();

        }

        public List<Person> ListOfPeople()
        {
            var _person = from one in db.Persons
                          select one;

            List<Person> list = _person.ToList();

            return list;
        }
    }
}

Update: this is the IService

[ServiceContract] public interface IService { [OperationContract] Person GetOnePerson(int BusinessEntityID);

    [OperationContract]
    List<Person> ListOfPeople();

}

Have I missed something?

Please advise me.

thanks,

Upvotes: 0

Views: 584

Answers (2)

Eddie Paz
Eddie Paz

Reputation: 2241

You have to decorate the Person class with the appropriate [DataContract] attribute and the fields you'd like to expose with [DataMember].

If you are using the DataEntity or LinqToSQL, which auto-generate classes for the table, note that is best practice to create a "data" class to be used by the service instead of sending a class that is part of your business logic. Take a look at the IDesign's WCF coding standards.

Upvotes: 1

BigL
BigL

Reputation: 1631

Check the Person classes implementation but i think it should be good because it is a generated class if i'm not mistaken.

Does your interface have the right Service Contract and Operation Contracts?

WCF tutorial

Upvotes: 0

Related Questions