简体   繁体   English

宁静的WCF服务和LINQ

[英]Restful WCF Service and LINQ

WCF Restful Webservice seems to be caching the LINQ data objects somehow. WCF Restful Web服务似乎正在以某种方式缓存LINQ数据对象。

The webservice is a WCF Restful Service build on .NET 4.0 and is currently running in my local ASP.net Dev Server. 该Web服务是基于.NET 4.0的WCF Restful Service,当前正在我的本地ASP.net Dev Server中运行。

I have a MSSQL 2008 database which contains a range of valid IP addresses which the webservice uses LINQ to validate against. 我有一个MSSQL 2008数据库,其中包含Web服务使用LINQ进行验证的一系列有效IP地址。 The mechanism that validates the client IP against the acceptable IP range from the DB works successfully as independently tested. 在DB可接受的IP范围内验证客户端IP的机制可以成功运行,并且经过独立测试。

SCENARIO: client IP is 127.0.0.1 valid IP range is: 127.0.0.0 to 127.0.0.5 场景:客户端IP为127.0.0.1,有效IP范围为:127.0.0.0至127.0.0.5

I perform a GET request from Fiddler to the webservice and it works as it should, by giving me back a nice 200 status code. 我执行了一个从Fiddler到Web服务的GET请求,通过给我一个200的状态码,它可以正常工作。 I then change the range in the DB to be 127.0.0.0 to 127.0.0.0 and still receive a 200 status code when I should be receiving a 401 status code. 然后,我将数据库中的范围从127.0.0.0更改为127.0.0.0,当我应该接收401状态代码时仍收到200状态代码。 I then go to Visual Studio and simply save a file (without any modifications) and return to Fiddler and reissue the request and I now get the desired 401 status code. 然后,我转到Visual Studio,仅保存一个文件(不做任何修改),然后返回Fiddler并重新发出请求,现在我得到了所需的401状态代码。

In the web service I am setting the Cache-Control and Pragma headers to "no-cache" which is present in the response: 在Web服务中,我将Cache-Control和Pragma标头设置为“ no-cache”,它出现在响应中:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 30 Jul 2010 16:12:56 GMT
X-AspNet-Version: 4.0.30319
Pragma: no-cache
Content-Length: 1121680
Cache-Control: no-cache
Content-Type: application/xml; charset=utf-8
Connection: Close

or.. 要么..

HTTP/1.1 401 Unauthorized
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 30 Jul 2010 16:26:48 GMT
X-AspNet-Version: 4.0.30319
Pragma: no-cache
Content-Length: 88
Cache-Control: no-cache
Content-Type: application/xml; charset=utf-8
Connection: Close

It seems to me that something in the LINQ process is caching the data that it originally got back from the first request and is not returning to the DB for each subsequent request. 在我看来,LINQ进程中的某些内容正在缓存它最初从第一个请求返回的数据,并且没有为每个后续请求返回到DB。 Once I save any file on the webservice, it causes recompilation of the service and thus performs another lookup to get the data. 一旦将任何文件保存在Web服务上,它将导致服务的重新编译,并因此执行另一次查找以获取数据。

Are you able to test your LINQ-to-SQL call directly, without going through the web service, just to verify that LINQ-to-SQL may be performing caching for you? 您是否可以通过LINQ-to-SQL直接测试您的LINQ-to-SQL调用而无需通过Web服务,只是为了验证LINQ-to-SQL是否可以为您执行缓存?

Also, here's a link to an issue that's similar to yours, and requires that you disable object tracking. 另外,这是指向与您类似的问题的链接 ,并且要求您禁用对象跟踪。 The default value of this property on your data context is true . 数据上下文中此属性的默认值为true The relevant section of the post: 该帖子的相关部分:

Your solution is to disable object tracking (caching for LINQ) of the data context like so. 您的解决方案是像这样禁用数据上下文的对象跟踪(缓存LINQ)。 myContext.ObjectTrackingEnabled = false;

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM