我已经看到了几个关于使用AJAX Web服务和接收错误的问题的帖子:
此服务的安全设置需要“匿名”身份验证,但不会为承载此服务的IIS应用程序启用此功能。
线程都有几个解决方案,至少对我来说没有工作,然后最后发布的“让它工作”,但是实际上从未给出了让它工作的方法。我正在使用支持AJAX的'WCF'服务开发一个网站。我无权访问服务器配置,因此更改服务器以允许匿名访问不是一种选择。当前网站配置适用于在本地主机开发计算机上运行站点的时间。但是,当网站发布到不允许匿名访问的服务器时,我收到上述错误。我创建了一个简单的AJAX服务,除了将字符串返回给调用JavaScript函数之外什么也不做。简单的设置仍然存在身份验证问题,导致我认为问题在于如何在Web.Config中定义AJAX服务的定义。任何建议让我超过上述错误,将不胜感激!我相信我需要让AJAX服务使用Windows身份验证,并且通过线程的研究已经解决了绑定类型和传输和消息使用的安全性。我尝试过黑色设置,NTLM和Windows,但我还没有找到成功的组合。
<?xml version="1.0"?>
<configuration>
<system.web>
<roleManager enabled="true" />
<sessionState cookieless="false" regenerateExpiredSessionId="true" />
<compilation debug="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" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>
</compilation>
<authentication mode="Windows" />
<identity impersonate="true" />
<pages enableViewStateMac='false' controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
validate="false" />
</httpHandlers>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<security>
<authentication>
<windowsAuthentication enabled="true" />
</authentication>
</security>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="default"/>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webScriptEnablingBehavior">
<enableWebScript/>
</behavior>
<behavior name="srvTestAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="srvTest" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="default"
contract="srvTest"
behaviorConfiguration="srvTestAspNetAjaxBehavior" />
</service>
</services>
</system.serviceModel>
</configuration>
答案 0 :(得分:2)
无需使用良好的旧Web服务。以下WCF配置适用于Windows或NTLM身份验证(我使用AutoCompleteExtender)
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="MyBindingForWindowsAuth">
<security mode="TransportCredentialOnly">
<!-- For Ntlm to work do => IIS right click Win Auth => Providers => Move NTLM up -->
<transport clientCredentialType="Windows" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="XYZ">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="Cms.OrderMacroService" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="MyBindingForWindowsAuth"
contract="Cms.OrderMacroService" behaviorConfiguration="XYZ" />
<endpoint address="mex" binding="webHttpBinding" bindingConfiguration="MyBindingForWindowsAuth" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
答案 1 :(得分:0)
我无法找到使用支持AJAX的WCF服务的解决方案,该服务器不允许匿名访问并强制使用Windows身份验证。为了解决这个问题,我最终将服务从支持AJAX的WCF服务(.SVC)更改为Web服务(.ASMX)。将其转换为使用Web服务并从Web.Config中删除对服务的引用,允许从JavaScript访问服务,不会导致验证错误。