簡體   English   中英

公開WCF服務元數據

[英]Exposing wcf service metadata

我正在遵循有關設置wcf服務的教程。 我完成了它所涉及的更改,直到它第一次啟動該服務為止。 在Web瀏覽器中導航到端點時,出現404或403.14錯誤。 最初,該服務顯示的是文件夾結構,但我在啟用該功能的web.config文件中刪除了該屬性。 我確定問題與該文件有關,但是我不確定還有什么要更改。 鏈接至指南: http : //www.c-sharpcorner.com/UploadFile/dhananjaycoder/four-steps-to-create-first-wcf-service-for-beginners/

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);
    }
}

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

在VS2015中,您可以將.svc文件設置為啟動文檔。 點擊“ F5”將在WCF測試客戶端(WcfTestClient.exe)中打開該文檔。 或者,您可以右鍵單擊.svc文件,然后選擇“在瀏覽器中查看”。

暫無
暫無

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

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