gpt4 book ai didi

c# - 在 WCF 服务上运行 svcutil.exe 时出现 OperationBehaviorAttribute 错误

转载 作者:行者123 更新时间:2023-11-30 22:40:38 28 4
gpt4 key购买 nike

当我尝试在 WCF 服务上运行 svcutil.exe 时,我遇到了一个非常奇怪的错误。

"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."

我已经在下面粘贴了我的代码,如果有人能对此有所说明,我将不胜感激。

我应该指出它适用于除“EditOpportunityProductTypes”之外的所有方法

我的界面:

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);
}
}

我的服务:

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);
}
}
}

最佳答案

您已经使用 OperationBehavior 属性修饰了 interface 中的 EditOpportunityProductTypes 方法:

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

你可能打算在那里使用 OperationContract:

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

关于c# - 在 WCF 服务上运行 svcutil.exe 时出现 OperationBehaviorAttribute 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5105831/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com