2010-02-08 34 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>