使用Windows身份验证调用WCF服务时无法执行URL
我在其部署的服务器之一上使用
Windows身份验证的WCF服务出现问题(它是Windows Server 2008 R2计算机),而在我可以访问的所有其他计算机上运行完美(Windows 7,Windows Server) 2008和Windows Server 2008 R2).我设法用一个非常简单的示例应用程序重现了这个问题,该应用程序或多或少完全排除了我的代码作为问题的原因.
我可以重现问题的最小应用程序是对WCF服务项目模板的一个小修改: [ServiceContract] public interface IService1 { [OperationContract] string GetData(int value); } [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] public class Service1 : IService1 { public string GetData(int value) { return string.Format("You entered: {0}nUsername: {1}",value,ServiceSecurityContext.Current == null ? "<null>" : ServiceSecurityContext.Current.PrimaryIdentity.Name); } } 基本上我启用了ASP.NET兼容性(我需要它,因为实际代码使用HttpHandler进行身份验证)并返回经过身份验证的用户的用户名. web.config的内容如下: <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Windows"/> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="ServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <basicHttpBinding> <binding name="HttpWindowsBinding" maxReceivedMessageSize="2147483647"> <readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647"/> <security mode="TransportCredentialOnly"> <transport clientCredentialType="Windows" /> </security> </binding> </basicHttpBinding> </bindings> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> <services> <service name="TestService.Service1" behaviorConfiguration="ServiceBehavior"> <endpoint address="" binding="basicHttpBinding" bindingConfiguration="HttpWindowsBinding" contract="TestService.IService1" /> <endpoint address="problem" binding="basicHttpBinding" bindingConfiguration="HttpWindowsBinding" contract="TestService.IService1" /> </service> </services> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration> 注意两个端点:一个具有默认地址,另一个具有相对地址.即使在有问题的服务器上调用第一个也成功,而对第二个调用的调用失败并出现以下错误: Exception type: HttpException Exception message: Failed to Execute URL. at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.BeginExecuteUrl(String url,String method,String childHeaders,Boolean sendHeaders,Boolean addUserIndo,IntPtr token,String name,String authType,Byte[] entity,AsyncCallback cb,Object state) at System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride,NameValueCollection requestHeaders,Object state) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context,AsyncCallback callback,Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) 当使用经典管道时,调用才会失败(因为HttpHandler我需要它,但即使没有它也可以重现问题).使用集成管道,问题就消失了.此外,如果我禁用Windows身份验证,问题也会消失: <binding name="HttpBinding" maxReceivedMessageSize="2147483647"> <readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647"/> <security mode="None"> <transport clientCredentialType="None" /> </security> </binding> 我注意到注册了HttpHandler的另一个细节.具有相对地址的端点的HttpRequest.CurrentExecutionFilePath属性的值在有问题的服务器(?/ Service1.svc / problem)和工作服务器(?/ Service1.svc)之间不同.虽然我对IIS不熟悉,但我怀疑这可能暗示问题的原因 – 可能与请求的路由有关? 我的想法已经不多了,因此我在这里张贴这篇文章,希望有人能够认识到问题所在.欢迎任何建议. 解决方法
您是否在IIS上打开了URL重写?这闻起来像是某种许可问题.
What is the difference between Classic and Integrated pipeline mode in IIS7?可能会有所帮助.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Windows如何在系统调用期间切换到管理员模式?
- 定时任务crontab命令详解
- 作为Windows管理员,您在尝试学习Linux发行版时遇到了哪些问
- Windows 10 – Windows 10中的哪个程序使用端口80?
- Windows – 将Azure网站迁移到Azure云服务
- Windows – Active Directory用户和计算机上的Active Direc
- windows-server-2012 – Windows Server 2012:添加/删除程
- windows-8 – 在.cpp文件中使用实现声明C/C++X WinRT属性的
- Microsoft SQL表可以有多个主键吗?
- character-encoding – Go:使用windows-1252编码写入文件