2

I'm getting a very strange error when I try to run svcutil.exe on a WCF service.

"OperationBehaviorAttribute can only go on the service class"

[InvalidOperationException]: OperationBehaviorAttribute can only go on the service class, it cannot be put on the ServiceContract interface. Method 'EditProduct' on type 'IProductWCF' violates this."

I have pasted my code below and if anybody can shed any light on this, I'd really appreciate it.

I should point out that it works on every method except "EditOpportunityProductTypes"

My Interface:

namespace ProductWCF { [ServiceContract] public interface IProductWCF { [OperationContract] string SayHello(AppointmentFeedback objAppointmentFeedback); [OperationContract] Boolean CreateAppointmentFeedback(AppointmentFeedback objAppointmentFeedback); [OperationContract] List<ExpiringContractType> GetOpportunityProductTypes(int opportunityId); [OperationBehavior] Boolean EditOpportunityProductTypes(List<ExpiringContractType> lstExpiringContractTypes, int opportunityId); } } 

My Service:

namespace ProductWCF { public class Service : IProductWCF { [OperationBehavior] public string SayHello(AppointmentFeedback objAppointmentFeedback) { return objAppointmentFeedback.Notes; } [OperationBehavior] public Boolean CreateAppointmentFeedback(AppointmentFeedback objAppointmentFeedback) { ProductData.CRM.Objects.AppointmentFeedback objNewAppointmentFeedback = new AppointmentFeedback(); if (objNewAppointmentFeedback.Insert(objAppointmentFeedback.AppointmentId, objAppointmentFeedback.StarId, objAppointmentFeedback.AppointmentStatusId, objAppointmentFeedback.Notes, objAppointmentFeedback.Creator, objAppointmentFeedback.AttendeeName) > 0) return true; else return false; } [OperationBehavior] public List<ExpiringContractType> GetOpportunityProductTypes(int opportunityId) { return OpportunityProductTypeMethods.GetOpportunityConnectionTypes(opportunityId); } [OperationBehavior] public Boolean EditOpportunityProductTypes(List<ExpiringContractType> lstExpiringContractTypes, int opportunityId) { return ProductData.CRM.Objects.OpportunityProductTypeMethods.UpdateOpportunityConnectionTypes(lstExpiringContractTypes, opportunityId); } } } 

1 Answer 1

3

You have decorated the EditOpportunityProductTypes method in the interface with the OperationBehavior attribute:

 [OperationBehavior] Boolean EditOpportunityProductTypes(List lstExpiringContractTypes, int opportunityId); 

You probably meant to use OperationContract there:

 [OperationContract] Boolean EditOpportunityProductTypes(List lstExpiringContractTypes, int opportunityId); 
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the comment. Is there any reason the other methods work and the only one that doesn't is EditOpportunityProductTypes?
@Nick: the other method are in the interface decorated with OperationContract as they should, so there is no problem with them.
I cannot believe I missed that! Thank you :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.