0

我正在使用的 WCF 服务有一个非常具体的问题:

我有一个带有 2 个下拉菜单的 ASP.NET 页面:

  • 第一个是从后面的 ASP.NET 代码中填充的。
  • 另一个是通过 jQuery ajax 调用从 WCF 服务填充的。

他们都使用模拟以登录用户身份访问 SQL Server 数据库。这适用于我们所有的客户,除了 1 个环境。尝试从 WCF 服务调用数据库时出现以下异常:

"Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'.","StackTrace":"   
                at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)\u000d\u000a   
                at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)\u000d\u000a   
                at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)\u000d\u000a   
                at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)\u000d\u000a   
                at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)\u000d\u000a 
...

似乎由于某种原因,WCF 服务正在使用匿名帐户访问数据库,尽管来自 ASP.NET 代码后面的调用仍然按预期工作并使用预期帐户访问数据库。连接字符串使用Integrated Security=SSPI. 它一定是我们缺少的一些特定于环境的配置,但我看不到委派和模拟直接从 ASP.NET 工作的确切内容。

有谁知道问题可能是什么?

编辑: system.servicemodel 部分:

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  <bindings>
  <webHttpBinding>
    <binding name="ServiceWebBindingName">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"></transport>
      </security>
    </binding>
  </webHttpBinding>     
</bindings>
<behaviors>
  <endpointBehaviors>     
    <behavior name="HistoryReportingEndpointBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="HistoryReportingServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceAuthorization principalPermissionMode="UseAspNetRoles" impersonateCallerForAllOperations="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
    <service behaviorConfiguration="HistoryReportingServiceBehavior" name="ServiceLibrary.HistoryReporting">
    <endpoint address="" behaviorConfiguration="HistoryReportingEndpointBehavior" binding="webHttpBinding" bindingConfiguration="ServiceWebBindingName" name="HistoryReportingWebEndPoint" contract="ServiceLibrary.IHistoryReporting" />
  </service>    
</services>
</system.serviceModel>
4

1 回答 1

0

您收到的错误可能是因为您的 Web 应用程序正在使用的 IIS 应用程序池在没有 SQL Server 权限的帐户下运行。将应用程序池帐户更改为可以访问 SQL Server 的帐户,问题应该会消失。

于 2013-11-02T00:50:13.637 回答