Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WCF服务上运行svcuti.exe时出现OperationBehaviorAttribute错误_C#_.net_Wcf_Exception Handling - Fatal编程技术网

C# 在WCF服务上运行svcuti.exe时出现OperationBehaviorAttribute错误

C# 在WCF服务上运行svcuti.exe时出现OperationBehaviorAttribute错误,c#,.net,wcf,exception-handling,C#,.net,Wcf,Exception Handling,当我尝试在WCF服务上运行svcuti.exe时,出现了一个非常奇怪的错误 “OperationBehaviorAttribute只能在服务类上运行” [InvalidOperationException]:OperationBehaviorAttribute只能放在服务类上,不能放在ServiceContract接口上。类型“IPProductWCF”上的方法“EditProduct”与此冲突。“ 我已经在下面粘贴了我的代码,如果有人能解释一下,我将非常感激 我应该指出,它适用于除“EditO

当我尝试在WCF服务上运行svcuti.exe时,出现了一个非常奇怪的错误

“OperationBehaviorAttribute只能在服务类上运行”

[InvalidOperationException]:OperationBehaviorAttribute只能放在服务类上,不能放在ServiceContract接口上。类型“IPProductWCF”上的方法“EditProduct”与此冲突。“

我已经在下面粘贴了我的代码,如果有人能解释一下,我将非常感激

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

我的界面:

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
{
[服务合同]
公共接口IPWCF
{
[经营合同]
字符串SayHello(任命反馈对象jappointfeedback);
[经营合同]
布尔CreateAppointFeedback(AppointFeedback对象JappointFeedback);
[经营合同]
列出GetOpportunityProductTypes(int opportunityId);
[操作行为]
布尔EditOpportunityProductTypes(列表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);
        }
    }
}
namespace-ProductWCF
{
公共类服务:IPWCF
{
[操作行为]
公共字符串SayHello(任命反馈objappointfeedback)
{
返回ObjPointFeedback.Notes;
}
[操作行为]
公共布尔CreateAppointFeedback(AppointFeedback对象JappointFeedback)
{    
ProductData.CRM.Objects.AppointFeedback objnewappointFeedback=新任命反馈();
if(objnewappointfeedback.Insert(objappointfeedback.AppointmentId,objappointfeedback.StarId,objappointfeedback.appointstatusid,objappointfeedback.Notes,objappointfeedback.Creator,objappointfeedback.attendename)>0)
返回true;
其他的
返回false;
}
[操作行为]
公共列表GetOpportunityProductTypes(int opportunityId)
{    
返回OpportunityProductTypeMethods.GetOpportunityConnectionTypes(opportunityId);
}
[操作行为]
公共布尔EditOpportunityProductTypes(列表lstExpiringContractTypes,int-opportunityId)
{
返回ProductData.CRM.Objects.OpportunityProductTypeMethods.UpdatePortUnityConnectionTypes(lstExpiringContractTypes,opportunityId);
}
}
}

您已使用
OperationBehavior
属性修饰界面中的
EditOpportunityProductTypes
方法:

 [OperationBehavior]
 Boolean EditOpportunityProductTypes(List lstExpiringContractTypes, int opportunityId);
您可能打算在那里使用
OperationContract

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

谢谢你的评论。有什么原因其他方法可以工作而唯一不能工作的是EditOpportunityProductTypes吗?@Nick:另一个方法在界面上用
OperationContract
装饰,所以它们没有问题。我不敢相信我错过了!谢谢:)