簡體   English   中英

被“遠程服務器返回錯誤:(403)禁止”與WCF服務在https中難倒

[英]Stumped by “The remote server returned an error: (403) Forbidden” with WCF Service in https

我有一個WCF服務,由於這個錯誤我已經歸結為幾乎沒有。 它把我推到了牆上。 這就是我現在擁有的。

一個非常簡單的WCF服務,其中一個方法返回一個值為“test”的字符串。

一個非常簡單的Web應用程序,它使用該服務並將字符串的值放入標簽中。

在Win 2003上運行IIS 6且具有SSL證書的Web服務器。

有效的同一服務器上的其他WCF服務。

我將WCF服務發布到它的https位置

我在VS中以調試模式運行Web應用程序,它運行良好。

我將Web應用程序發布到WCF服務所在的同一服務器上的https位置,該服務器位於相同的SSL證書下

我明白了,“遠程服務器返回錯誤:(403)Forbidden”

我幾乎已經改變了IIS中的每個設置以及WCF和Web應用程序都無濟於事。 我已經比較了WCF服務中的設置和一切都是一樣的。

以下是WCF服務和WEB應用程序的web.config中的設置:

看來這個問題與Web應用程序有關,但我沒有想法。 有任何想法嗎:

WCF服務:

  <system.serviceModel>
<bindings>

<client />

<services>
  <service behaviorConfiguration="Ucf.Smtp.Wcf.SmtpServiceBehavior" name="Ucf.Smtp.Wcf.SmtpService">
    <host>
      <baseAddresses>
        <add baseAddress="https://test.net.ucf.edu/webservices/Smtp/" />
      </baseAddresses>
    </host>
    <endpoint address="" binding="wsHttpBinding" contract="Ucf.Smtp.Wcf.ISmtpService" bindingConfiguration="SSLBinding">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="Ucf.Smtp.Wcf.SmtpServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" httpsHelpPageEnabled="True"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

網絡應用:

    <system.serviceModel>
    <bindings><wsHttpBinding>
<binding name="WSHttpBinding_ISmtpService" closeTimeout="00:01:00"
 openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
 bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
 maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
 textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
 <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
 <reliableSession ordered="true" inactivityTimeout="00:10:00"
  enabled="false" />
 <security mode="Transport">
  <transport clientCredentialType="None" proxyCredentialType="None"
   realm="" />
  <message clientCredentialType="Windows" negotiateServiceCredential="true"
   establishSecurityContext="true" />
 </security>
</binding>

<client>


<endpoint address="https://net228.net.ucf.edu/webservices/smtp/SmtpService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ISmtpService"
contract="SmtpService.ISmtpService" name="WSHttpBinding_ISmtpService">
<identity>
 <dns value="localhost" />
</identity>

  </client>
</system.serviceModel>

在花費數小時和數小時來解決這個問題之后,我將回答我自己的問題。 我希望這有助於所有其他人在牆上試圖解決這個問題。 我們終於有一個網絡管理員參與並解決了這個問題

這是場景和解決方案:

我們有一個生產服務器 - 一切正常。 我們有一個測試服務器 - 我們得到403禁止錯誤。 本地調試工作正常。

我們想到的所有設置都是相同的。

有一個設置是錯誤的。 在IIS中,在“目錄安全性”選項卡下的Web服務虛擬目錄的屬性中,第二個“編輯”按鈕用於IP限制。 我們設置為拒絕訪問所有IP,除了應該包含測試服務器的IP的列表。 測試Web服務器的IP未被授予權限。 它沒有權限的原因是它最近從生產虛擬服務器克隆,並且從未調整此設置以添加測試虛擬服務器。

在我的情況下,我從另一台機器復制了源代碼,並且此處尚未創建虛擬目錄。 一旦我去了項目屬性並創建了虛擬目錄,它工作正常。

跳出來的唯一一件事就是你將Windows標識與消息一起傳遞,如果傳遞的用戶帳戶無權訪問WCF服務,這可能會導致權限問題。 可能需要假冒網絡應用程序?

默認情況下,WCF綁定不允許匿名(無身份驗證)訪問。 您需要修改綁定以允許它:

  <wsHttpBinding> 
    <binding ...> 
        <security mode ="None"/> 
    </binding> 
  </wsHttpBinding>

在我的情況下,我的apppool用戶由於某種原因沒有對'C:\\ Windows \\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ Temporary ASP.NET Files'的讀/寫訪問權限。

確保你有compilation debug="true"設置。

暫無
暫無

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

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