dragoncmd
dragoncmd

Reputation: 234

Exposing wcf service metadata

I'm following a tutorial on setting up a wcf service. 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. Initially the service was showing the folder structure, but I removed the attribute in the web.config file that was enabling that. 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/

Web.config file:

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

Upvotes: 0

Views: 1711

Answers (1)

Dennis
Dennis

Reputation: 346

I think the 403.14 may be related to your folder permissions. What account is your application pool running under and the version of .NET Framework? Make sure you're app pool is targeting 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. Than, try removing protocolMapping.

In VS2015 you can set .svc file as a start up document. Hitting "F5" will open that document in WCF Test Client (WcfTestClient.exe). Alternatively, you can right-click the .svc file and select "View in Browser".

Upvotes: 2

Related Questions