1

我有一个使用 Windows 身份验证的启用了 WCF ajax 的 Web 服务,当我在本地 PC 上运行该应用程序时,它运行良好,但是当我托管它时,它不想通过客户端凭据传递给该服务。

我不断收到此错误: 用户“NT AUTHORITY\ANONYMOUS LOGON”登录失败

我相信我已经包含了所有必要的配置,但我不确定。

我的网络配置:

    <?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <system.web>
    <authentication mode="Windows"/>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <connectionStrings>
    <add name="reportEntities" connectionString="metadata=res://*/Entities.TNTReport.csdl|res://*/Entities.TNTReport.ssdl|res://*/Entities.TNTReport.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=UECZATNT02;initial catalog=report;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
  <!--<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="PassThrough">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="TNTQueryEngine.Services.InformationServicesAspNetAjaxBehavior">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <services>
      <service name="TNTQueryEngine.Services.InformationServices">
        <endpoint address="" behaviorConfiguration="TNTQueryEngine.Services.InformationServicesAspNetAjaxBehavior"
          binding="webHttpBinding" contract="TNTQueryEngine.Services.InformationServices" />
      </service>
    </services>
  </system.serviceModel>-->
  <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" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceAuthorization principalPermissionMode="UseAspNetRoles" impersonateCallerForAllOperations="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="XYZ">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="TNTQueryEngine.Services.InformationServices" behaviorConfiguration="MyServiceTypeBehaviors">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="MyBindingForWindowsAuth"
                  contract="TNTQueryEngine.Services.InformationServices" behaviorConfiguration="XYZ" />
        <endpoint address="mex" binding="webHttpBinding" bindingConfiguration="MyBindingForWindowsAuth" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

我的 WCF 服务有 1 种方法:

namespace TNTQueryEngine.Services
{
    [ServiceContract(Namespace = "InfoServices")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class InformationServices 
    {
        reportEntities RP = new reportEntities();
        [OperationContract, WebGet(ResponseFormat = WebMessageFormat.Json)]
        [OperationBehavior(Impersonation = ImpersonationOption.Required)]
        public List<Receiving> GETReceiving(DateTime DATE)
        {
            return (from SS in RP.spQueryEngineGETReceivingSummary(DATE)
                    where SS.QTY > 0
                    select new Receiving
                    {
                        ReceivedDate = DATE,
                        Model = SS.Model,
                        Qty = (int)SS.QTY
                    }
                    ).ToList();
        }

    }
}

真的不知道可能出了什么问题。提前感谢您的帮助

4

0 回答 0