WCF REST 服务 - 401 未经授权
我们正在开发一个 WCF REST Web 服务,该服务仅从任何匿名用户接收一堆任意文本,然后在后端执行一些处理。
例如,以下是我们的 Web 服务中的一种方法:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class MyRESTService : IMyRESTService
{
[WebInvoke(Method = "PUT", UriTemplate = "/MyRESTMethod?paramA={paramA}¶mB={paramB}")]
public Stream MyRESTMethod(string paramA, string paramB, Stream rawData)
{
//do some stuff...
}
}
如果我们仅使用默认的 IIS 设置,我们会收到 (401) Unauthorized
。然而,经过多次试验和错误,我们发现可以通过向我们服务的实际 .svc
文件上的“每个人”授予写入访问权限来使其正常工作。
我的问题是:为什么 IIS 需要对 .svc
文件具有写入访问权限才能正常工作?有没有更好的方法或者我是否坚持这种黑客(并且可能不安全)的解决方法?
微软什么鬼?
可能相关:
We're in the process of developing a WCF REST web service which just receives a bunch of arbitrary text from any anonymous user and then performs some processing on the back end.
For example, here's one method from our web service:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class MyRESTService : IMyRESTService
{
[WebInvoke(Method = "PUT", UriTemplate = "/MyRESTMethod?paramA={paramA}¶mB={paramB}")]
public Stream MyRESTMethod(string paramA, string paramB, Stream rawData)
{
//do some stuff...
}
}
If we just use the default IIS settings we get a (401) Unauthorized
. However, after much trial and error we figured out that we could get it to work by giving WRITE access to 'Everyone' on the actual .svc
file for our service.
My question is: why in the world would IIS need to have WRITE access to an .svc
file for this to work? Is there a better way or am I stuck with this hackish (and possibly insecure) workaround?
WTF Microsoft?
Possibly related:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还发现可以通过将
放入
中的web.xml 中来解决此问题。配置
I have also found this can be fixed by putting
<authentication mode="None" />
inside of<system.web>
in yourweb.config
在与 M$ 的技术代表交谈后,我得知这确实是预期的行为。该服务必须启用写访问权限,以便某人向其发送请求,当您执行此操作时,它实际上也会自动在 .SVC 文件上设置写访问权限。
After talking to a tech representative from M$ I was informed that this is indeed the expected behavior. The service must have write access enabled for someone to send a request to it, and when you do this it will actually set write access automatically on the .SVC file as well.