WCF REST服务导致404

时间:2012-08-12 23:38:34

标签: wcf rest

我已经阅读了大部分WCF REST 404帖子,但没有一篇能帮助我......

我已成功构建了WCF REST服务。但是,现在它引起了问题。我尝试创建一个示例WCF REST服务,如果不使用.SVC,我就无法使用它。

这就是我的代码

 [ServiceContract]
    public interface IService1
    {
        [WebGet(UriTemplate="data")]
        [OperationContract]
        string GetData();
    }

 public class Service1 : IService1
    {
        public string GetData()
        {
            return "1";
        }
    }

这就是我在web.config中的内容

<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="Default" name="RESTService.Service1">
        <endpoint address="http://mydomain:8888/Service1.svc" 
                  binding="webHttpBinding" 
                  contract="RESTService.IService1" 
                  behaviorConfiguration="Web" />
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
      <behavior name="Web">
        <webHttp />
      </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>

</configuration>

当我转到http://mydomain:8888/data时,会在404中做出响应。任何想法为什么它没有点击GetData()函数?如果我删除端点地址

,则以下URL有效
http://mydomain:8888/Service1.svc/data

但是,我希望地址为http://mydomain:8888/data

1 个答案:

答案 0 :(得分:1)

您可以尝试将Web配置保留在正常工作的版本中(路径中包含svc),并在应用程序启动期间在全局asax文件中添加路由表条目

查看更多信息

http://msdn.microsoft.com/en-us/library/cc668177.aspx

相关问题