我创建了一个 IIS -hosted WCF OData-service 两个从 MS-SQL数据库发布表。当我尝试从自定义 C#项目访问该服务时,我收到一条错误消息,指出'NT-AUTHORITY \ ANONYMOUS'无法访问数据库。
IIS 配置为模拟用户,当我从浏览器请求相同的网址时,我会获取数据,所以我怀疑我自己的 C# - 应用程序正在执行请求,由于某种原因,用户没有正确模拟。
以下是事实:
validateIntegratedModeConfiguration
已关闭。 以下是我的客户端代码片段:
var serviceContextContext = new DataServiceContext(_url);
_serviceContextContext.IgnoreMissingProperties = true;
_serviceContextContext.IgnoreResourceNotFoundException = true;
_serviceContextContext.SendingRequest += DataServiceContextContextSendingRequest;
// Here is where I get an internal server error
var response = _serviceContextContext.Execute<ODataEntity>(entitySetRequestUri);
private void DataServiceContextContextSendingRequest(object sender, SendingRequestEventArgs e)
{
var request = (HttpWebRequest)e.Request;
request.Credentials = new NetworkCredential(_user, _password,_domain);
}
这是小提琴手给我的东西:
浏览器请求1 - 响应为401
GET http://localhost/WcfDataService.svc/Table/?$select=Something HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: de-DE,de;q=0.8,en-US;q=0.5,en;q=0.3
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: localhost
DNT: 1
Connection: Keep-Alive
浏览器请求2 - 响应为401
GET http://localhost/WcfDataService.svc/Table/?$select=Something HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: de-DE,de;q=0.8,en-US;q=0.5,en;q=0.3
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Authorization: NTLM TlRMTVNTUAABAAAAB7IIogIAAgA0AAAADAAMACgAAAAGA9ckAAAAD0RFTEwyMDEzMDYwMUwy
DNT: 1
Connection: Keep-Alive
Host: localhost
浏览器请求3 - 响应为200 - &gt;工作!
GET http://localhost/WcfDataService.svc/Table/?$select=Zusatz HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: de-DE,de;q=0.8,en-US;q=0.5,en;q=0.3
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: localhost
DNT: 1
Connection: Keep-Alive
Authorization: NTLM TlRMTVNTUAADAAAAAAAAAFgAAAAAAAAAWAAAAAAAAABYAAAAAAAAAFgAAAAAAAAAWAAAAAAAAABYAAAABcKIogYD1yQAAAAP9oJm9T9LmMQahBlQzRd2XA==
自定义应用程序请求1 - 响应为401
GET http://localhost/WcfDataService.svc/Table/?$select=Something HTTP/1.1
User-Agent: Microsoft ADO.NET Data Services
MaxDataServiceVersion: 2.0;NetFx
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8
Host: localhost
自定义应用程序请求2 - 响应为401
GET http://localhost/WcfDataService.svc/Table/?$select=Zusatz HTTP/1.1
User-Agent: Microsoft ADO.NET Data Services
MaxDataServiceVersion: 2.0;NetFx
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8
Authorization: NTLM TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAGA9ckAAAADw==
Host: localhost
自定义应用程序请求3 - 响应为500 - &gt; FAILED!
GET http://localhost/WcfDataService.svc/Table/?$select=Zusatz HTTP/1.1
User-Agent: Microsoft ADO.NET Data Services
MaxDataServiceVersion: 2.0;NetFx
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8
Authorization: NTLM TlRMTVNTUAADAAAAGAAYAIQAAABWAVYBnAAAAAQABABYAAAAEAAQAFwAAAAYABgAbAAAAAAAAADyAQAABYKIogYD1yQAAAAPgBZZaTO9a5O7HFjtoe2STmwAMgBmAGgAZQByAHQAZQBsAGwARABFAEwATAAyADAAMQAzADAANgAwADEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAS+24pX5KSeSdFgQ3uQ9wrwEBAAAAAAAAr9kbQ+2UzgHeWK0bawVaUgAAAAACAAQATAAyAAEAGABEAEUATABMADIAMAAxADMAMAA2ADAAMQAEABgATABhAHkAZQByADIALgBsAG8AawBhAGwAAwAyAEQARQBMAEwAMgAwADEAMwAwADYAMAAxAC4ATABhAHkAZQByADIALgBsAG8AawBhAGwABQAYAEwAYQB5AGUAcgAyAC4AbABvAGsAYQBsAAcACACv2RtD7ZTOAQYABAACAAAACAAwADAAAAAAAAAAAAAAAAAwAABAWMQ+SOQSOHP+7RN68GTo7ZpLSdYRekIYD8N3LRL0xwoAEAAAAAAAAAAAAAAAAAAAAAAACQAsAEgAVABUAFAALwBsAG8AYwBhAGwAaABvAHMAdAAuAGYAaQBkAGQAbABlAHIAAAAAAAAAAAAAAAAA
Host: localhost
在回复中,我收到以下错误消息:
Cannot open database "TEST" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'
所以我得出结论,我的请求与浏览器请求有所不同,这阻止了模拟正常工作。
我真的很感激任何提示。