Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 我可以通过web.config让WCF 4 REST服务端点工作吗?_Asp.net_Wcf_Web Services_Rest - Fatal编程技术网

Asp.net 我可以通过web.config让WCF 4 REST服务端点工作吗?

Asp.net 我可以通过web.config让WCF 4 REST服务端点工作吗?,asp.net,wcf,web-services,rest,Asp.net,Wcf,Web Services,Rest,我正在搞清楚WCF/REST的东西。我的目标是创建端点没有扩展的服务,因此我创建了一个简单的WCF服务: namespace SampleWebSite { [ServiceContract()] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class ContactService {

我正在搞清楚WCF/REST的东西。我的目标是创建端点没有扩展的服务,因此我创建了一个简单的WCF服务:

namespace SampleWebSite 
{
    [ServiceContract()]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ContactService
    {
        [WebGet(UriTemplate = "all", ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        public string[] Sample()
        {
            return new string[] { "Bill Gates", "Paul Allen", "Steve Ballmer" };
        }
    }
}
所以,我希望它的功能可以通过有意义的URL获得,比如。我可以通过将以下代码放在Global.asax文件中轻松实现这一点:

void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes();
}

void RegisterRoutes() 
{
    RouteTable.Routes.Add(new ServiceRoute("ctsvc", new WebServiceHostFactory(), typeof(SampleWebSite.ContactService)));
}
现在,我想知道我是否可以摆脱这些代码,并将所有的魔法转移到web.config文件中。这件事我已经坚持了好几天,没有任何结果。我当前的配置如下:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
      <service name="SampleWebSite.ContactService" behaviorConfiguration="Meta">
        <endpoint name="rest"
              address="ctsvc"
              binding="webHttpBinding"
              contract="SampleWebSite.ContactService"
              behaviorConfiguration="REST" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="REST">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Meta">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="ctsvc" helpEnabled="true" automaticFormatSelectionEnabled="false"/>
      </webHttpEndpoint>
    </standardEndpoints>
</system.serviceModel>

从Global.asax中删除代码并使用此配置会导致我不断出现404错误。我做错什么了吗