【发布时间】:2019-12-08 05:47:39
【问题描述】:
我一直在关注 Microsoft tutorial。关于设置启用 AJAX 的 WCF 服务并使用客户端访问它们。但是,尽管完全按照教程进行操作,但由于错误,结果不会按预期显示。具体来说,错误表明枚举约束失败,导致“名称”和“合同”属性无效。
错误似乎源自我的Web.config 文件,因为错误列表仅显示该文件中的问题。下面我包含了文件中的代码,以及我尝试访问的服务中的代码。
//The service model segment of the configuration file.
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="SandwichServices.Service1AspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="SandwichServices.CostServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="SandwichServices.CostService">
<endpoint address="" behaviorConfiguration="SandwichServices.CostServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="SandwichServices.CostService" />
</service>
</services>
</system.serviceModel>
//The .svc.cs file for my service
using System.ServiceModel;
using System.ServiceModel.Activation;
namespace SandwichServices
{
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class CostService
{
[OperationContract]
public double CostOfSandwiches(int quantity)
{
return 1.25 * quantity;
}
}
}
Web.config 文件中出现以下错误消息:
“合同”属性无效 - 值 “SandwichServices.CostService”根据其数据类型无效 'serviceContractType' - 枚举约束失败。" " “名称”属性无效 - 值“SandwichServices.CostService” 根据其数据类型“serviceNameType”无效 - 枚举约束失败。
【问题讨论】:
-
我刚刚遵循了相同的教程并遇到了同样的问题 - 它对我也不起作用。你找到解决方案了吗?