大佬教程收集整理的这篇文章主要介绍了使用Windows身份验证调用WCF服务时无法执行URL,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我可以重现问题的最小应用程序是对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进行身份验证)并返回经过身份验证的用户的用户名.
<?xml version="1.0"?> <configuration> <sy@L_262_13@.web> <compilation debug="true" targetFramework="4.0" /> <authentication mode="Windows"/> </sy@L_262_13@.web> <sy@L_262_13@.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> </sy@L_262_13@.serviceModel> <sy@L_262_13@.webServer> <modules runAllManagedModulesForAllrequests="true"/> </sy@L_262_13@.webServer> </configuration>
注意两个端点:一个具有默认地址,另一个具有相对地址.即使在有问题的服务器上调用第一个也成功,而对第二个调用的调用失败并出现以下错误:
Exception type: httpException Exception message: Failed to Execute URl. at Sy@L_262_13@.Web.HosTing.ISAPIWorkerrequesTinProcForIIS6.beginExecuteUrl(String url,String method,String childHeaders,@R_772_8487@an sendHeaders,@R_772_8487@an addUserIndo,IntPtr token,String name,String authType,Byte[] entity,AsyncCallBACk cb,Object statE) at Sy@L_262_13@.Web.httpResponse.beginExecuteUrlForEntireResponse(String pathOverride,NameValueCollection requestHeaders,Object statE) at Sy@L_262_13@.Web.DefaulthttpHandler.beginProcessrequest(httpContext context,AsyncCallBACk callBACk,Object statE) at Sy@L_262_13@.Web.httpApplication.CallHandlerEXECUTIONStep.Sy@L_262_13@.Web.httpApplication.IEXECUTIONStep.Execute() at Sy@L_262_13@.Web.httpApplication.ExecuteStep(IEXECUTIONStep step,@R_772_8487@an& 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不熟悉,但我怀疑这可能暗示问题的原因 – 可能与请求的路由有关?
以上是大佬教程为你收集整理的使用Windows身份验证调用WCF服务时无法执行URL全部内容,希望文章能够帮你解决使用Windows身份验证调用WCF服务时无法执行URL所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。