2

潜入 WCF RESTful 服务并遇到以下错误:

>“/”应用程序中的服务器错误。

 IIS specified authentication schemes 'None', but the binding only supports
 specification of exactly one authentication scheme. Valid authentication
schemes are Digest, Negotiate, NTLM, Basic, or Anonymous.
Change the IIS settings so that only a single authentication scheme is used. 

这是场景:

我正在开发一个使用路由.svc从 URL 中删除的 WCF 服务。这样我就可以到达http://mySite/MyService. 当我启用匿名身份验证时,这非常有效。

为了做到这一点,我遵循了 Steve Michelotti 的教程“RESTful WCF Services with No svc file and No config”

代码分解为以下内容:

我的实际服务等级是:

Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports System.ServiceModel.Activation

 Namespace Service

<ServiceContract()> _
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class Product

    <OperationContract()> _
    <WebInvoke(Method:="GET")> _
    Public Function GetProducts() As String
        Return "Listing ALL Products"
    End Function

End Class

结束命名空间

在“Global.asax”文件中启用了路由,如下所示:

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    RouteTable.Routes.Add(New ServiceRoute("Product", New WebServiceHostFactory(), GetType(Service.Product)))
End Sub

我的“web.config”看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <add name="OLAPIBasicAuthModule" type="Service.ServiceValidator" />
    </modules>
    <security>
        <authentication>
            <windowsAuthentication enabled="false" />
            <anonymousAuthentication enabled="false" />
            <basicAuthentication enabled="false" />
        </authentication>
    </security>
</system.webServer>

<system.web>
    <httpRuntime requestValidationMode="2.0" />
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
        <assemblies>
            <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        </assemblies>
    </compilation>
</system.web>

<system.serviceModel>        
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>      

现在,为了处理基本身份验证,我遵循了Mike Volodarsky 关于“使用 .NET 开发模块”的教程

这基本上给了我一个验证请求的类。

当我运行调试器时,浏览器会向我请求用户名/密码。当我输入它们时,它会通过我的自定义验证器进行验证并返回 true,但是,服务调用随后会失败,并出现此问题顶部的错误。

正如我所说,如果我启用匿名身份验证一切正常。我可以访问http://mySite/Product/GetProducts并返回我的测试字符串。

我在 web.config 中尝试了许多条目,设置各种服务/绑定/行为等来启用基本身份验证,尽管它们通常会导致上述错误。

我有一种感觉,因为我在混合技术;IE 使用路由来调用我的服务,而不是使用端点等。

也就是说,目前我对 WCF 服务的理解非常有限。

最终,我需要能够使用路由(在 URL 中否定 .svc)并启用基本身份验证,但有我自己的自定义验证器,因为用户名/密码将在 SQL 中,对服务器/IIS 本身没有帮助。

有任何想法吗?

哦......我也在我的配置中试过这个:

<bindings>
        <basicHttpBinding>
            <binding name="httpBinding">
                <security mode="Transport">
                    <transport clientCredentialType="Basic" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>

仍然导致同样的错误

4

0 回答 0