2010-02-08 37 views
2

我的团队使用forms-authentication构建内部托管的ASP.NET MVC网站。如何在没有表单身份验证的虚拟目录中公开WCF服务?

我想在与ASP.NET MVC网站相同的虚拟目录中托管WCF服务。

我的问题:

How do I make the WCF service freely accessible, that is without forms-authentication.

我目前的困境是:

  • 我可以访问.SVC,看到了WSDL的信息,如果我第一次通过表单的身份验证与Web浏览器进行身份验证。
  • 但是当我尝试访问与wcfTestClient.exe WCF服务,我得到以下错误:

Error: Cannot obtain Metadata from http://localhost/Services/MyService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error

回答

1

非常感谢所有谁试图回答这个问题。

小时对此问题进行故障排除后,我发现自定义身份验证模块拒绝了我的客户端获取元数据的尝试。只需说一句,我需要绕过这个逻辑。

噢 - 单步代码很低被低估。 ;)

1

如果你可以把你的.svc文件到虚拟目录的子文件夹,你可以在表单身份验证中利用路径属性以使用不同级别的授权对其进行访问。 Here is a tutorial

2

您是否在web.config中为服务定义了mex endpoint?测试客户端可能正在寻找这个。

如果这样做,另一种可能是禁用对services文件夹的授权。我从来没有测试过这个,但理论上它可能工作...

所以,如果网站是localhost,把WCF服务在localhost/services/myservice.svc或类似的。然后一个web.config添加到/services文件夹,它覆盖的授权,并允许所有:

<configuration> 
    <authorization> 
     <allow users="*" /> 
    </authorization> 
</configuration> 
1

我假设,因为你使用的是虚拟目录配置为在IIS匿名访问窗体身份验证。这就是说,如果你把你的WCF服务,例如* .svc文件存放在其自己的目录中,您可以更新主web.config文件并添加位置标记以禁用包含该服务的目录的表单身份验证。另外,请务必通过在web.config的<system.servicemodel>部分的WCF配置绑定设置需要被,如果不存在添加到确定停用安全:

<bindings> 
    <wsHttpBinding> <!-- one of many possible bindings --> 
    <binding name="...">   
     <security mode="None"> <-- allows anonymous access --> 
     <message clientCredentialType="None"/> <-- allows anonymous access --> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings>