wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用Windows身份验证调用WCF服务时无法执行URL大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我在其部署的服务器之一上使用 Windows身份验证的WCF服务出现问题(它是Windows Server 2008 R2计算机),而在我可以访问的所有其他计算机上运行完美(Windows 7,Windows Server) 2008和Windows Server 2008 R2).我设法用一个非常简单的示例应用程序重现了这个问题,该应用程序或多或少完全排除了我的代码作为问题的原因. 我可以重现问
我在其部署的服务器之一上使用 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>
  <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不熟悉,但我怀疑这可能暗示问题的原因 – 可能与请求的路由有关?

我的想法已经不多了,因此我在这里张贴这篇文章,希望有人能够认识到问题所在.欢迎任何建议.

解决方法

您是否在IIS上打开了URL重写?这闻起来像是某种许可问题. What is the difference between Classic and Integrated pipeline mode in IIS7?可能会有所帮助.

大佬总结

以上是大佬教程为你收集整理的使用Windows身份验证调用WCF服务时无法执行URL全部内容,希望文章能够帮你解决使用Windows身份验证调用WCF服务时无法执行URL所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。