English 中文(简体)
wcf 返回无效数据
原标题:wcf returns invalid data

我有一个基于EF4模型、以IIS7.5.5公布的网站服务测试(REST),其中一项基本查询是:

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

然后我做一个测试电话 用以下的url在e9:

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 服务, 第二个请求将会生效, 因此显然与 IS 有联系吗? FSP 和用户之间有许多关联 。

任何指定的帮助/ 指针

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

如果这是您应用程序中真实的代码示例, 那么您就不应该像我看到的那样, 将上下文作为每个创建的服务实例来对待 。

您应该更改上下文, 以创建一个有使用语句的示例, 在返回所需的数据后处置该语句。 这应该修正您的错误 。

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);
        }
     }
问题回答

暂无回答




相关问题
WCF DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

Access WCF service on same server

I have a .NET website with a WCF service. How do I access the current operations context of my service? One possible work around is to just make a call to the service within the app...but that seems ...

WCF binding error

So I got into work early today and got the latest from source control. When I try to launch our ASP.NET application, I get this exception: "The binding at system.serviceModel/bindings/wsHttpBinding ...

The service operation requires a transaction to be flowed

I am facing strange issue with our WCF service. The same code was working fine until recently we added more OperationContracts(Web Methods). We have common 3 tier architecture. DAL (WCF) BLL Web ...

热门标签