我有一个基于 EF4 模型并在 IIS7.5 上发布的测试 wcf webservice (REST)。基本查询之一是
public CfgUser GetUser(string fspId, string userName)
{
return _context.Users.FirstOrDefault(a => a.FspID == fspId && a.UserName == userName && a.WadtDeleted == false);
}
然后我在 ie9 中使用以下 url 进行测试调用:
https://10.201.2.70/webservices/service.svc/rest/GetUser(EDS,kern)
XML 数据正确返回。SQL 探查器显示
exec sp_executesql N'SELECT TOP (2)
[Extent1].[UserId] AS [UserId],
[Extent1].[FSP] AS [FSP],
[Extent1].[UserGroupId] AS [UserGroupId],
[Extent1].[ContactID] AS [ContactID],
[Extent1].[UserName] AS [UserName],
[Extent1].[UserPassword] AS [UserPassword],
[Extent1].[FirstName] AS [FirstName],
[Extent1].[MidName] AS [MidName],
[Extent1].[LastName] AS [LastName],
[Extent1].[CommonName] AS [CommonName],
[Extent1].[enumUserType] AS [enumUserType],
[Extent1].[enumActive] AS [enumActive],
[Extent1].[CreatedBy] AS [CreatedBy],
[Extent1].[wadtDeleted] AS [wadtDeleted],
[Extent1].[wadtModifiedBy] AS [wadtModifiedBy],
[Extent1].[wadtModifiedOn] AS [wadtModifiedOn],
[Extent1].[wadtModifiedOnDTOffset] AS [wadtModifiedOnDTOffset],
[Extent1].[wadtRowID] AS [wadtRowID],
[Extent1].[CreatedOn] AS [CreatedOn],
[Extent1].[CreatedOnDTOffset] AS [CreatedOnDTOffset],
[Extent1].[Email] AS [Email],
[Extent1].[isDeviceUser] AS [isDeviceUser],
[Extent1].[rowguid] AS [rowguid],
[Extent1].[PasswordHash] AS [PasswordHash],
[Extent1].[PasswordModifiedOn] AS [PasswordModifiedOn]
FROM [dbo].[cfgUsers] AS [Extent1]
WHERE (''EDS'' = [Extent1].[FSP]) AND ([Extent1].[UserName] = @p__linq__0) AND (0 =
[Extent1].[wadtDeleted])',N'@p__linq__0 varchar(8000)',@p__linq__0='kern'
如果我再用 url 立即调用:
https://10.201.2.70/webservices/service.svc/rest/GetUser(recserv,recserv-admin)
我收到请求错误。似乎 EF linq 查询保留了传递给原始 fspId 参数的值,即“EDS”。SQL 探查器显示
exec sp_executesql N'SELECT TOP (2)
[Extent1].[UserId] AS [UserId],
[Extent1].[FSP] AS [FSP],
[Extent1].[UserGroupId] AS [UserGroupId],
[Extent1].[ContactID] AS [ContactID],
[Extent1].[UserName] AS [UserName],
[Extent1].[UserPassword] AS [UserPassword],
[Extent1].[FirstName] AS [FirstName],
[Extent1].[MidName] AS [MidName],
[Extent1].[LastName] AS [LastName],
[Extent1].[CommonName] AS [CommonName],
[Extent1].[enumUserType] AS [enumUserType],
[Extent1].[enumActive] AS [enumActive],
[Extent1].[CreatedBy] AS [CreatedBy],
[Extent1].[wadtDeleted] AS [wadtDeleted],
[Extent1].[wadtModifiedBy] AS [wadtModifiedBy],
[Extent1].[wadtModifiedOn] AS [wadtModifiedOn],
[Extent1].[wadtModifiedOnDTOffset] AS [wadtModifiedOnDTOffset],
[Extent1].[wadtRowID] AS [wadtRowID],
[Extent1].[CreatedOn] AS [CreatedOn],
[Extent1].[CreatedOnDTOffset] AS [CreatedOnDTOffset],
[Extent1].[Email] AS [Email],
[Extent1].[isDeviceUser] AS [isDeviceUser],
[Extent1].[rowguid] AS [rowguid],
[Extent1].[PasswordHash] AS [PasswordHash],
[Extent1].[PasswordModifiedOn] AS [PasswordModifiedOn]
FROM [dbo].[cfgUsers] AS [Extent1]
WHERE (''EDS'' = [Extent1].[FSP]) AND ([Extent1].[UserName] = @p__linq__0) AND (0 =
[Extent1].[wadtDeleted])',N'@p__linq__0 varchar(8000)',@p__linq__0='recserv-admin'
如果我重新启动 IIS 服务,那么第二个请求将起作用,那么显然某处与 IIS 有联系?FSP 和用户之间存在一对多关联。
任何帮助/指针