WCF +基本身份验证 - 不会停止使用匿名身份验证
我一直在尝试创建一个使用基本身份验证的 WCF 服务,到目前为止,我一直收到一条错误消息,表明该服务需要匿名身份验证,即使我认为我已将 web.config 配置为使用基本身份验证。
我花了几个小时尝试但未能找到解决问题的方法,所以我想在这里尝试一下。我怀疑这是我忽略的事情。
这就是我正在做的事情。我创建了一个 Web 项目,添加了一个 wcf 服务,创建了另一个 Web 项目,并添加了一个 .aspx 页面来测试该服务。我没有更改默认 wcf 服务配置中的任何内容。我可以部署到 IIS,如果我打开浏览器窗口并导航到该页面,一旦启用匿名身份验证,该服务就可以正常工作。我还可以使用测试页面访问该服务,没有任何问题。
然后,我将服务更改为使用基本身份验证(请参阅下面的服务的 web.config)并重新部署。我没有将 IIS 的身份验证更改为使用基本身份验证,因此仍然设置为使用匿名身份验证。我刷新了浏览器并显示了服务。测试网页仍然能够访问该服务。
然后,我将 IIS 中的身份验证方案更改为使用 Basic,并确保禁用所有其他类型的身份验证。当我尝试访问该服务时,收到错误消息:“此服务的安全设置需要‘匿名’身份验证,但托管此服务的 IIS 应用程序未启用该身份验证。”
这是我的服务的 web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<wsHttpBinding>
<binding name="basicAuthBinding">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="TestService">
<endpoint address="http://localhost:7000/BA.svc" binding="wsHttpBinding" bindingConfiguration="basicAuthBinding" name="BasicEndpoint" />
</service>
</services>
</system.serviceModel>
</configuration>
您知道为什么这不起作用吗?
I’ve been trying to create a WCF service that uses Basic Authentication and so far I keep hitting an error message indicating that the service wants Anonymous authentication even though I thought I'd configured the web.config to use Basic auth.
I spent a few hours trying and failing to find a solution to my problem, so I wanted to give it a try here. I suspect it's something I'm overlooking.
Here's what I'm doing. I created a web project, added a wcf service, created another web project, and added a single .aspx page to test the service. I didn’t change ANYTHING in the default wcf service config. I can deploy to IIS and if I open a browser window and navigate to the page, the service works fine once I enable anonymous authentication. I can also use the test page to access the service without any issues.
Then, I changed the service to use basic auth (see below for the service's web.config) and redeployed. I didn't change IIS's authentication to use Basic, so it was still set to use Anonymous authentication. I refreshed the browser and the service displayed. The test web page was still able to access the service.
Then, I changed the authentication scheme in IIS to use Basic and made sure all other types of authentication were disabled. When I tried to access the service I received the error message, “Security settings for this service require ‘Anonymous’ Authentication but it is not enabled for the IIS application that hosts this service.”
Here is my service’s web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<wsHttpBinding>
<binding name="basicAuthBinding">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="TestService">
<endpoint address="http://localhost:7000/BA.svc" binding="wsHttpBinding" bindingConfiguration="basicAuthBinding" name="BasicEndpoint" />
</service>
</services>
</system.serviceModel>
</configuration>
Any ideas why this isn't working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
遵循 中的一些建议如何在 IIS 中仅使用 basichttpbinding、SSL 和基本身份验证来使用 WCF?,您可以将 wsHttpBinding 替换为 basicHttpBinding,设置
并在 IIS 上启用 SSL?或者由于某种原因这不是您想要的托管服务的方式?
Following some suggestions in How can I use WCF with only basichttpbinding, SSL and Basic Authentication in IIS?, can you replace your wsHttpBinding by a basicHttpBinding, set
<serviceMetadata httpsGetEnabled="true" />
and enable SSL on your IIS?Or is this for some reason not the way you want to host your service?