简体   繁体   English

公开WCF服务元数据

[英]Exposing wcf service metadata

I'm following a tutorial on setting up a wcf service. 我正在遵循有关设置wcf服务的教程。 I finished the changes it talks about, up to the first time it says to start the service. 我完成了它所涉及的更改,直到它第一次启动该服务为止。 When navigating to the endpoint in my web browser I either get a 404 or 403.14 error. 在Web浏览器中导航到端点时,出现404或403.14错误。 Initially the service was showing the folder structure, but I removed the attribute in the web.config file that was enabling that. 最初,该服务显示的是文件夹结构,但我在启用该功能的web.config文件中删除了该属性。 I'm sure the issue is related to that file, but I'm not sure what else to change. 我确定问题与该文件有关,但是我不确定还有什么要更改。 Link to the guide: http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/four-steps-to-create-first-wcf-service-for-beginners/ 链接至指南: http : //www.c-sharpcorner.com/UploadFile/dhananjaycoder/four-steps-to-create-first-wcf-service-for-beginners/

Web.config file: 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>

Service Contract: 服务合同:

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

I think the 403.14 may be related to your folder permissions. 我认为403.14可能与您的文件夹权限有关。 What account is your application pool running under and the version of .NET Framework? 您的应用程序池在哪个帐户下运行以及.NET Framework的版本? Make sure you're app pool is targeting Framework 4.0. 确保您的应用程序池定位于Framework 4.0。 403.14 - most likely you're trying to browse the root directory and directory browsing is disabled in IIS or your app pool doesn't have enough permissions. 403.14-您极有可能尝试浏览根目录,并且在IIS中禁用了目录浏览,或者您的应用程序池没有足够的权限。 Than, try removing protocolMapping. 比,尝试删除protocolMapping。

In VS2015 you can set .svc file as a start up document. 在VS2015中,您可以将.svc文件设置为启动文档。 Hitting "F5" will open that document in WCF Test Client (WcfTestClient.exe). 点击“ F5”将在WCF测试客户端(WcfTestClient.exe)中打开该文档。 Alternatively, you can right-click the .svc file and select "View in Browser". 或者,您可以右键单击.svc文件,然后选择“在浏览器中查看”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 wcf服务中的公开方法 - exposing method in wcf service WCF测试客户端:无法添加服务。可能无法访问服务元数据。确保您的服务正在运行并公开元数据 - WCF Test Client : Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata WCF无法添加服务。 可能无法访问服务元数据。 确保您的服务正在运行并公开元数据 - WCF Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata 添加服务失败。 服务元数据可能无法访问。 确保您的服务正在运行并公开元数据。 WCF错误 - Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata. WCF Error WCF:无法添加服务。 可能无法访问服务元数据。 确保您的服务正在运行并公开元数据 - WCF: Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata WCF 服务未公开绑定信息 - WCF service is not exposing binding information WCF服务中缺少元数据 - Missing MetaData In WCF Service WCF服务元数据错误 - WCF service metadata error 获取WCF服务元数据 - Getting WCF Service Metadata WCF服务在2个不同的服务合同上公开2个终结点 - WCF service exposing 2 endpoints on 2 different service contracts
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM