How to set up WCF REST web service?

Discussion in 'ASP.NET WebServices' started by MikeDodaro, Nov 9, 2011.

  1. I have a WCF REST web service that works fine on Visual Studio dev server but fails when I publish it to the discountAspNet server.

    All I get with a GET request is the directory browsing page.
    When I try POST request the error is "method not allowed".
     
  2. WCF REST web service set up

    I have a WCF REST web service that works fine on Visual Studio dev server but fails when I publish it to the discountAspNet server.

    All I get with a GET request is the directory browsing page.
    When I try POST request the error is "method not allowed".
     
  3. glad it worked out, but your solution is not universal

    Your solution is not necessarily true for all environments. Apparently your Service or client accesses or consumes from multiple sites, which necessitated using the multiplesitebindingsenabled switch. However, in an actual WCF REST service solution that I successfully uploaded and use in DiscountASP.net, in fact leaving in this switch created problems. The WCF REST solution only worked when I removed <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> and replaced it with:

    <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
    <add prefix="http://MYDISCOUNTASPDOTNETWEBSITENAMEHERE.com" />
    </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

    The actual working Web.config file for this solution is shown below, with a few changes made for privacy.

    PJ


    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <system.web>
    <compilation targetFramework="4.0">
    <assemblies>
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c689334e049" />
    </assemblies>
    </compilation>
    </system.web>
    <system.serviceModel>
    <services>
    <service name="ARestServiceName.ARestServiceNameImpl" behaviorConfiguration="ServiceBehaviour">
    <!-- Service Endpoints -->
    <!-- Unless fully qualified, address is relative to base address supplied above -->
    <endpoint address="" binding="webHttpBinding" contract="ARestServiceName.IARestServiceNameImpl" behaviorConfiguration="web">
    <!--
    Upon deployment, the following identity element should be removed or replaced to reflect the
    identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
    automatically.
    -->
    </endpoint>
    </service>
    </services>
    <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
    <add prefix="http://MYDISCOUNTASPDOTNETWEBSITENAMEHERE.com" />
    </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
    <behaviors>
    <serviceBehaviors>
    <behavior name="ServiceBehaviour">
    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
    <serviceMetadata httpGetEnabled="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="false" />
    </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
    <behavior name="web">
    <webHttp />
    </behavior>
    </endpointBehaviors>
    </behaviors>
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    <connectionStrings>DELETED</connectionStrings>
    </configuration>
     

Share This Page