簡體   English   中英

無法通過HTTPS獲得WCF休息服務

[英]Can't get WCF rest service working over HTTPS

我們有一個運行的ASP.NET應用程序,我已經添加了一個WCF Rest服務。 在本地和在測試環境中部署時,這可以正常工作。 問題是當我們部署到我們的生產環境時,它只是HTTPS。

我在網上搜索並閱讀了大部分答案並嘗試了很多東西。 一切都沒有運氣。

這是我們簡單的代碼

[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)]有關。我們使用它來確保用戶已經過身份驗證,我們可以訪問令牌。 一旦WCF服務被移動到SSL ,我發現PrincipalPermission.Demand()失敗 ,遺憾的是它沒有答案。

討厭回答我自己的問題,但在閱讀了Rajesh的消息后,我更多地調查了錯誤。 正如我的編輯所說,它與PrincipalPermission屬性有關。 如果我刪除了它正在運行我的代碼並且我的身份驗證失敗了。

回到搜索互聯網,我找到了http://forums.silverlight.net/t/34954.aspx/1

我剛剛加入了serviceBehaviours。 所以它看起來像

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

現在它可以工作,我可以調用我的服務並被拒絕,除非我通過身份驗證等等

希望這可以幫助其他人解決這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM