2016-06-06 30 views
0

我正在關注設置wcf服務的教程。我完成了它所談論的改變,直到它第一次啓動服務。在Web瀏覽器中導航到端點時,我得到404或403.14錯誤。最初該服務正在顯示文件夾結構,但我刪除了啓用該功能的web.config文件中的屬性。我確定這個問題與該文件有關,但我不確定還有什麼可以改變的。 鏈接到指南:http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/four-steps-to-create-first-wcf-service-for-beginners/公開wcf服務元數據

Web.config文件:

<?xml version="1.0"?> 
<configuration> 

    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5.2"/> 
    <httpRuntime targetFramework="4.5.2"/> 
    <httpModules> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/> 
    </httpModules> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="WcfCalculator.Calculator" behaviorConfiguration="Metadata"> 
     <endpoint address="" contract="WcfCalculator.ICalculator" binding="basicHttpBinding"/> 
     <endpoint name="mex" address="mex" contract="IMetadataExchange" binding="mexHttpBinding"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="Metadata"> 
      <serviceMetadata httpGetEnabled="true"/> 
     </behavior> 
     <behavior> 
      <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
      <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https"/> 
    </protocolMapping>  
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="ApplicationInsightsWebTracking"/> 
     <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" 
     preCondition="managedHandler"/> 
    </modules> 
    <!-- 
     To browse web app root directory during debugging, set the value below to true. 
     Set to false before deployment to avoid disclosing web app folder information. 
     --> 
    <validation validateIntegratedModeConfiguration="false"/> 
    </system.webServer> 

</configuration> 

服務合同:

using System.ServiceModel; 

namespace WcfCalculator 
{ 
    [ServiceContract] 
    public interface ICalculator 
    { 
     [OperationContract] 
     double AddNumbers(double number1, double number2); 
     [OperationContract] 
     double SubstractNumbers(double number1, double number2); 
     [OperationContract] 
     double MultiplyNumbers(double number1, double number2); 
     [OperationContract] 
     double DivisionNumbers(double number1, double number2); 
    } 
} 

回答

2

我認爲403.14可能與您的文件夾權限。您運行的應用程序池和.NET Framework的版本是哪個帳戶?確保您的應用程序池的目標是Framework 4.0。 403.14 - 很可能您嘗試瀏覽根目錄並且在IIS中禁用了目錄瀏覽,或者您的應用程序池沒有足夠的權限。比嘗試刪除protocolMapping。

在VS2015中,您可以將.svc文件設置爲啓動文檔。點擊「F5」將在WCF Test Client(WcfTestClient.exe)中打開該文檔。或者,您可以右鍵單擊.svc文件並選擇「在瀏覽器中查看」。

+0

你是什麼意思關於「什麼帳戶」?它的目標.net版本4.5.2。我假設它試圖瀏覽該文件夾,並關閉了文件夾瀏覽功能,但是我應該打開哪些內容才能進入該屏幕? http://i.imgur.com/oIWulna.png我現在只是通過Visual Studio託管服務。它不在IIS上。 – dragoncmd

+0

好的,您使用的是卡西尼,而不是IIS。你說你看到了文件夾結構並且禁用了它 - 如果你沒有將服務設置爲啓動文檔,它會導致403錯誤。您也可以右鍵單擊svc文件並在瀏覽器中查看它。再次,不知道爲什麼你有協議映射。我將使用您所關注示例中提供的配置文件,並添加您需要的任何內容,例如應用程序見解和SSL。 – Dennis

+0

添加關於右鍵點擊.svc文件的信息到答案,我會接受它。 – dragoncmd