简体   繁体   中英

Failed to map path whem configuring WCF REST service for IIS 7.5

I am having an issue building and deploying WCF Rest services with IIS 7.5. If I open Visual Studio 2010 and create a new project of type "WCF Service Application" and then publish that to IIS it works fine. However, when I try to specify a WebGet Property on the operation contract from the IService.cs interface I get an error.

Interface (from IService.cs):

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebGet(UriTemplate = "hello/?n={name}")]
    Message SayHello(string name);
}

Corresponding Method (from Service.svc):

public Message SayHello(string name) {
   return Message.CreateMessage(MessageVersion.None, "*", "Hello "+name+"!");
}

I try to publish this to an IIS application I created (http://localhost/rest/) under my root site (http://localhost/) and the publish works successfully, however when I attempt to visit any page from the browser I get the following error:

Failed to map the path '/rest'.

I also tried changing the UriTemplate to [WebGet(UriTemplate = "rest/hello/?n={name}")] and I get the same error.

I am using the default configuration file from IIS:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

I should also mention that I am using an application pool for .NET 4.0.

Please help as I am very puzzled by this.

Thanks in advance!

Jeffrey Kevin Pry

Since no one seemed to be interested in the question:) I figured it out on my own.

It seems that I had to do the following to get it working:

  1. Open Command Prompt (cmd.exe)
  2. cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ (will vary depending on setup)
  3. Execute aspnet_regiis.exe -i

That did the trick. It is all working now. Hopefully I can save someone a few hours or so of Googling.

Thanks,

Jeffrey Kevin Pry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM