2012-06-26 53 views
3

我們有一個ASP.NET應用程序正在運行,並且我已經爲其添加了WCF Rest服務。在本地和部署在測試環境中時,這可以正常工作。問題出在我們部署到我們只有HTTPS的生產環境中。無法通過HTTPS獲取WCF休息服務

我在網上搜索和閱讀了大多數答案,並嘗試了很多東西。所有沒有運氣。

這裏是我們簡單的代碼

[ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class ReportingService 
{ 
    public ReportingService() 
    { 
     Thread.CurrentPrincipal = HttpContext.Current.User; 
    } 

    [OperationContract] 
    [WebGet(UriTemplate = "get/{id}", ResponseFormat = WebMessageFormat.Json)] 
    [PrincipalPermission(SecurityAction.Demand)] 
    public List<RawReportTable> GetReport(string id) 
    { 
     ... 
    } 
} 

在Global.asax.cs中,我們有

RouteTable.Routes.Add(new ServiceRoute("api/reporting", new WebServiceHostFactory(), typeof(ReportingService))); 

在我們的web.config中,我們有以下的system.serviceModel

定義

<standardEndpoints> 
    <webHttpEndpoint> 
    <standardEndpoint name="api" helpEnabled="true" automaticFormatSelectionEnabled="true" maxBufferSize="500000" maxReceivedMessageSize="500000">   
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
     <security mode="Transport" /> 
    </standardEndpoint> 
    </webHttpEndpoint> 
</standardEndpoints> 

<behaviors> 
    <endpointBehaviors> 
    <behavior name="api"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 

    <serviceBehaviors> 
    <behavior name=""> 
     <serviceCredentials> 
      <serviceCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" findValue="d5 85 5b 37 89 47 6f 89 71 5b b7 5d 87 6f 2e e5 24 aa 57 b6" /> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<services> 
    <service name="ReportingService"> 
    <endpoint address="api/reporting" behaviorConfiguration="api" binding="webHttpBinding" bindingConfiguration="webBinding" contract="WayfinderFM.Service.api.ReportingService" /> 
    </service> 
</services> 

<bindings> 
    <webHttpBinding> 
    <binding name="webBinding"> 
     <security mode="Transport" /> 
    </binding> 
    </webHttpBinding> 
</bindings> 

使用此設置,我收到以下錯誤: 請求錯誤:服務器在處理請求時遇到錯誤。查看服務器日誌獲取更多詳細信

我認爲(和一些例子顯示)我不再需要在配置中的服務/端點的東西,因爲它是在路由中註冊的。

刪除那部分我們仍然得到相同的錯誤。我嘗試了很多不同的配置,都沒有運氣。

奇怪的是/ api/reporting/help實際顯示。只是不能使用任何服務。

有人有什麼想法嗎?我希望這是我錯過的簡單東西。

感謝所有

編輯

我相信這是與 [的PrincipalPermission(SecurityAction.Demand) 我們用它來確保用戶進行身份驗證,我們可以訪問做令牌。我發現PrincipalPermission.Demand() failing once WCF Service was moved to SSL,可悲的是沒有答案。

+0

什麼是錯誤你得到?資源未找到或錯誤的請求或內部服務器錯誤?當您使用standardendpoint元素時,也請刪除服務部分。您的證書findValue也有空格。你可以嘗試刪除空格嗎?可能是沒有找到證書 – Rajesh

+0

所以今天早上我添加了(不知道爲什麼我還沒有那個!)。現在顯示的錯誤是服務器在處理請求時遇到錯誤。異常消息是'訪問被拒絕'。 - 我無法弄清楚爲什麼我不能訪問 – lukem

回答

6

討厭回答我自己的問題,但在閱讀了Rajesh的消息之後,我更加關注了這個錯誤。正如我的編輯所說,它與PrincipalPermission屬性有關。如果我刪除了它正在運行我的代碼並且未通過身份驗證。

所以回到搜索互聯網,我發現http://forums.silverlight.net/t/34954.aspx/1

我剛纔添加到serviceBehaviours。所以它看起來像

<serviceBehaviors> 
    <behavior name=""> 
     <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" /> 
     <serviceAuthorization principalPermissionMode="None"/> 
    </behavior> 
</serviceBehaviors> 

現在的作品,我可以打電話給我的服務和被拒絕,除非我認證等耶

希望這有助於別人這個問題