Ehsan Akbar February 2016

The OperationContractAttribute declared on method 'method' in type 'service' is invalid. in wcf

I am trying to make a WCF service in visual studio as you can see here:

[ServiceContract]
    public interface IReportSRC{

           [OperationContract]
        List<tblArticle> ReturnArticleList();

        [OperationContract]
       int ReturnArticleListCount();

         [OperationContract]
        List<tblPayment> ReturnPaymentList();

         [OperationContract]
         int ReturnPaymentSum();

         [OperationContract]
        List<tblNew> ReturnNews();

         [OperationContract]
        List<tblUserInfo> ReturnUsers();

         [OperationContract]
        int ReturnUsersCount();

         [OperationContract]
        List<tblUserInfo> ReturnReviewers();

         [OperationContract]
        List<tblSponsor> ReturnsSponser();

    }

So i implement this Interface as you can see in my service :

[AspNetCompatibilityRequirements(
        RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ReportSRC : IReportSRC
    {
        dblinqtoDb.dbDataContext db=new dbDataContext();


        List<tblArticle> IReportSRC.ReturnArticleList()
        {
            return db.tblArticles.ToList();
        }

        public List<tblPayment> ReturnPaymentList()
        {
            return db.tblPayments.ToList();
        }

        public List<tblNew> ReturnNews()
        {
            return db.tblNews.ToList();
        }
        [OperationContract(IsOneWay = true)]
        public List<tblUserInfo> ReturnUsers()
        {
            return db.tblUserInfos.ToList();
        }

        public List<tblUserInfo> ReturnReviewers()
        {
            List<tblUserInfo> res =
                (from i in db.tblUserInfos
                 join b in db.tblUserLogins on i.Username equals b.Username
                 where b.IsJuror == "1"
                 select i).ToList();
            return res;

        }

            

Answers


Ehsan Akbar February 2016

The problem was this line of code in implementation layer of interface :

 [OperationContract(IsOneWay = true)]

When i remove this line everything works fine .but i don't know why?


sudheer kondala February 2016

Why do you want to specify operation contract in implementation class? You can specify in interface with one way attribute like below and it will work fine.

[OperationContract(IsOneWay=true)]
List<tblUserInfo> ReturnUsers();


carlosfigueira February 2016

The error message is a little misleading. Indeed, you should not declare the operation contract in the class - but you have already declared it in the interface.

However, if you try to declare it (as a one-way operation, one that the client calls and doesn't get any response) in the interface, you'll have another error - one-way methods can only be declared in methods that don't return anything (i.e., that "return" void).

Post Status

Asked in February 2016
Viewed 1,222 times
Voted 9
Answered 3 times

Search




Leave an answer