Snuffleupagus
Snuffleupagus

Reputation: 6755

WCF service returning 404 on method requests

I have a WCF service page running only WebGets/WebInvokes over SSL - it works fine on my local machine (self signed cert). On production, however, I can reach service.svc (and it gives me the message about how to consume) but service.svc/AnyRequest returns a 404. Both environments are hosted in IIS 7.5.

I've enabled tracing and the service isn't even picking up any of the method requests (e.g. service.svc/SomeRequest), however it is processing service.svc just fine. It's also listening at https://computername.domain.net/path/service.svc - is this normal? Should it normally be pointing to https://publicfacing.com/path/service.svc?

Also note that the production server is hosting multiple sites within IIS.

Below is the system.serviceModel section of my web.config. The SSLBehave was suggested from here.

  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="TransportSecurity">
          <security mode="Transport">
            <transport clientCredentialType="None"></transport>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="SSLBehave">
          <useRequestHeadersForMetadataAddress>
            <defaultPorts>
              <add scheme="https" port="443"/>
            </defaultPorts>
          </useRequestHeadersForMetadataAddress>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="UserManagement.ajaxAspNetAjaxBehavior">
          <webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <services>
      <service name="UserManagement.ajax" behaviorConfiguration="SSLBehave">
        <endpoint address="" behaviorConfiguration="UserManagement.ajaxAspNetAjaxBehavior"
          binding="webHttpBinding" bindingConfiguration="TransportSecurity" contract="UserManagement.ajax" />
      </service>
    </services>
  </system.serviceModel>

Upvotes: 33

Views: 59637

Answers (9)

Matt L
Matt L

Reputation: 55

I tried the above solutions, installing WCF Services, ensuring that there were proper permissions in the API directory and several other things.

While some of those were issues there was one issue for me that isn't mentioned above.

If Request Filtering is enabled for the entire server or the given site, make sure that .svc is a trusted file name extension, otherwise it will be blocked. Go to IIS > Request Filtering. Click on Edit Feature Settings. Check to see if "allow unlisted file extensions" is checked. If so, make sure that there is an entry in the list for .svc. Otherwise IIS will block the file from being served.

Upvotes: 0

Darkseal
Darkseal

Reputation: 9564

The first thing I do whenever I hit a 404 with a newly-developed WCF Web Service is checking the handler mapping required to interpret this type of call, because it's often the cause of the issue. There are several ways to work around the problem, many of which require a manual execution of the ServiceModelReg.exe console command: these are undoubtedly valid procedures but might also not work – or create additional problems – if your development machine has a particularly complex configuration. The resolution method I propose below is slightly longer to pull off, but has the advantage of solving the problem more safely and securely.

  • Open the Server Manager interface for machine management, usually present in both the Task Bar and the Start menu.
  • Go to the Dashboard (or Control Panel) and select Add Role or Feature to open the Wizard.
  • Select the Role-based or Feature-based installation type and the server you want to work on, that is, your local / local server.
  • Go to the Features section: Once there, expand the .NET Framework 3.5 Features node and / or the .NET Framework 4.5 Features node, depending on what you have installed: if you have both, you should perform the following step twice (for each one of them).
  • Expand the WCF Services section (if available), then select HTTP Activation (see screenshot below).
  • Continue until you complete the Wizard, then click Install.

enter image description here

Once the installation is complete, you should be able to run your WCF Service without incurring in the 404 error ever again.

For additional info regarding this specific issue and how to fix it, you can also read this post on my blog.

Upvotes: 30

Iomm1
Iomm1

Reputation: 91

The following setting in web.config fixed a WCF .svc 404 on a HTTPS web site :

      <webHttpBinding>
             <!-- https -->
             <security mode="Transport">
                    <transport clientCredentialType = "None" proxyCredentialType="None"/>
            </security>
    </binding>
  </webHttpBinding>

Upvotes: 1

OfirD
OfirD

Reputation: 10510

To help others that find themselves stuck with this - It may be that your service name is not the fully qualified name, which it must be.

Upvotes: 3

Dan Leksell
Dan Leksell

Reputation: 540

Perhaps in your RouteConfig.cs file add this line:

routes.IgnoreRoute("{resource}.svc/{*pathInfo}");

So long as your .svc file is in the root of the application.

Upvotes: 5

Kambiz Shahim
Kambiz Shahim

Reputation: 2590

As you mentioned you can access your service by .svc extension service.svc but not in REST format service.svc/AnyRequest, the problem must be in routing integration.

add this to your web.config

 <system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </modules>
  <handlers>
    <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
  </handlers>
 </system.webServer> 

In the IIS 6 The cause of this error must be Check that file exists setting of svc extention, make sure "Check that file exists is unchecked". For more information see IIS Hosted Service Fails.

Upvotes: 4

Only You
Only You

Reputation: 2072

You can implement transport level security using WsHttp bindings. See this article; in your bindings try this biding instead:

<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>

The article mentions you should tie up the bindings with the end points.

Upvotes: 7

Jeffrey Kinzer
Jeffrey Kinzer

Reputation: 149

I had the same problem. From what I read, WCF isnt NT Authenticated authorization (or HTTPContext compatible) by default.

I had to add this to my config file for the WCF service web.config in the section:

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

Which you did, plus this:

And on the actual service class definiation I had to add:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DataService : IDataDeliveryServiceContract

This fixed my problem.

Upvotes: 6

Derek Nigel Bartram
Derek Nigel Bartram

Reputation: 303

I would start by checking a number of things;

  • Permissions on the hosted directory?
  • .Net version is correct?
  • Have you added the certificate to the site?
  • Try putting an image in the same path, can you navigate to that (rule out the odd occasional path mappings)

Good luck!

Upvotes: 15

Related Questions