如何正确托管连接到IIS中的SQLServer的WCF数据服务?为什么我会收到错误?

Jor*_*mer 7 c# wcf iis-7 wcf-data-services

我正在玩WCF数据服务(ADO.NET数据服务).我有一个指向AdventureWorks数据库的实体框架模型.

当我从Visual Studio中调试我的svc文件时,它工作得很好. 我可以说/awservice.svc/Customers并取回我期望的ATOM提要.

如果我将服务(在ASP.NET Web应用程序中托管)发布到IIS7,则相同的查询字符串将返回500错误.根svc页面本身按预期工作并成功返回ATOM./ Customers路径失败.

这是我的授权在svc文件中的样子:

public class AWService : DataService<AWEntities>
{
    public static void InitializeService( DataServiceConfiguration config )
    {
        config.SetEntitySetAccessRule( "*", EntitySetRights.All );
        config.SetServiceOperationAccessRule( "*", ServiceOperationRights.All );
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }
}
Run Code Online (Sandbox Code Playgroud)

更新:我启用了详细错误并在XML消息中获取以下内容:

<innererror>
<message>The underlying provider failed on Open.</message>
<type>System.Data.EntityException</type>
<stacktrace>
   at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(
...
...
<internalexception>
<message>
Login failed for user 'IIS APPPOOL\DefaultAppPool'.
</message>
<type>System.Data.SqlClient.SqlException</type>
<stacktrace>
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, ...
Run Code Online (Sandbox Code Playgroud)

Pha*_*bus 8

在我看来,这是一个SQL身份验证错误,IIS正在一个无法访问您的SQL服务器的用户下运行其appPool,当您在Visual Studio(本地)中毁了它将是一个不同的用户.检查用户服务器上的IIS正在使用的用户,并确保它有权在SQL中执行您想要的操作.

  • @Pharabus - 你是个天才.我不得不修改DefaultAppPool使用的Identity帐户.这是一篇关于如何执行此操作的文章:http://technet.microsoft.com/en-us/library/cc771170%28WS.10%29.aspx.默认情况下,它使用的是低权限帐户.将它设置为LocalSystem就可以了. (2认同)