【问题标题】:Exposing wcf service metadata公开 wcf 服务元数据
【发布时间】:2016-06-06 21:55:56
【问题描述】:

我正在关注有关设置 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);
    }
}

【问题讨论】:

    标签: c# web-services wcf web-config


    【解决方案1】:

    我认为 403.14 可能与您的文件夹权限有关。您的应用程序池在什么帐户下运行以及 .NET Framework 的版本?确保您的应用程序池面向 Framework 4.0。 403.14 - 很可能您正在尝试浏览根目录并且目录浏览在 IIS 中被禁用,或者您的应用程序池没有足够的权限。然后,尝试删除协议映射。

    在 VS2015 中,您可以将 .svc 文件设置为启动文件。点击“F5”将在 WCF 测试客户端 (WcfTestClient.exe) 中打开该文档。或者,您可以右键单击 .svc 文件并选择“在浏览器中查看”。

    【讨论】:

    • “什么帐户”是什么意思?它的目标是 .net 版本 4.5.2。我假设它试图浏览文件夹,我关闭了文件夹浏览,但我应该打开什么才能进入这个屏幕? i.imgur.com/oIWulna.png 我现在只是通过 Visual Studio 托管服务。它还没有在 IIS 上。
    • 好的,您使用的是 Cassini,而不是 IIS。您说您看到了文件夹结构,然后将其禁用 - 如果您不将服务设置为启动文档,则会导致 403 错误。您也可以右键单击 svc 文件并在浏览器中查看。再说一次,不知道为什么你有协议映射。我将使用您所遵循的示例中提供的配置文件,而不是添加您需要的任何内容,例如应用洞察和 SSL。
    • 答案中添加右键.svc文件的信息,我接受。
    猜你喜欢
    • 2011-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多