2017-09-16 138 views
0

这是我的第一个Web服务,我试图按照教程上的Web服务创建一个自定义的验证,我坚持,因为我得到这个错误:WCF Web服务不能在Web Access服务名称配置

“WcfOrderingService.Services.AuthenticationTokenService”值根据其数据类型“serviceNameType”无效 - 枚举约束失败。

web配置:

 <service name ="WcfOrderingService.Services.AuthenticationTokenService" 
      behaviorConfiguration="ServiceBehaviourHttp"> 
    <endpoint address="" behaviorConfiguration="WcfOrderingService.AuthenticationTokenServiceAspNetAjaxBehavior" 
     binding="webHttpBinding" contract="WcfOrderingService.Services.AuthenticationTokenService.Authenticate" /> 
    </service> 

.svc.cs -

namespace WcfOrderingService.Services 
{ 
[ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class AuthenticationTokenService 
{ 
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, 
    ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] 
    [OperationContract] 
    public string Authenticate(Credentials creds) 
    { 
     ICredentialsValidator validator = new CredentialsValidator(); 
     if (validator.IsValid(creds)) 
      return new TokenBuilder().Build(creds); 
     throw new InvalidCredentialException("Invalid credentials"); 
    } 
} 

}

我已经试过我在网上找到的大多数事情,服务名称等的变化,但无法找到一个答案。

在此先感谢。

回答

0

可能对服务的引用无法正常工作了。这可能有几个原因。

该解决方案将首先删除servicereference,然后再次添加它。

+0

谢谢,但如果我甚至开始了一个全新的WCF服务应用程序项目,然后添加一个WCF服务(支持Ajax)服务 - 它给了我同样的错误。 –

+0

啊,我认为配置不正确。当您将端点的合同属性更改为WcfOrderingService.Services.AuthenticationTokenService时,它会起作用吗? –

+0

它不起作用intellisense也没有选择它,默认的service1虽然。 –