0

EF4 モデルに基づいて IIS7.5 で公開されたテスト wcf Web サービス (REST) があります。基本的なクエリの 1 つは、

 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 サービスを再起動すると、2 番目の要求が機能するので、明らかに IIS との関係がどこかにあるのでしょうか? FSP とユーザーの間には 1 対多の関連付けがあります。

適切なヘルプ/ポインタ

4

1 に答える 1

1
 public CfgUser GetUser(string fspId, string userName)
     {
     return _context.Users.FirstOrDefault(a => a.FspID == fspId && a.UserName == userName && a.WadtDeleted == false);
     }

これがアプリの実際のコード例である場合、作成されたすべてのサービス インスタンスでコンテキストを作成されたインスタンスとして扱うように、フィールドを持つべきではありません。

コンテキストを変更して、必要なデータが返された後に破棄する using ステートメントを使用してインスタンスを作成する必要があります。これでエラーが修正されます。

public CfgUser GetUser(string fspId, string userName)
     {
        using (MyEntities _context = new MyEntities())
        {
     return _context.Users.FirstOrDefault(a => a.FspID == fspId && a.UserName == userName && a.WadtDeleted == false);
        }
     }
于 2012-05-22T07:20:09.873 に答える