Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
C# 如何在wcf中使用路由表调用端点?_C#_Wcf_Asp.net Routing - Fatal编程技术网

C# 如何在wcf中使用路由表调用端点?

C# 如何在wcf中使用路由表调用端点?,c#,wcf,asp.net-routing,C#,Wcf,Asp.net Routing,我创建了一个演示web应用程序,其中我尝试使用不包含svc文件的wcf服务。基本上,我尝试将路由添加到routetable,就像我们在asp.net mvc中添加的一样 我在这里引用了: 代码: [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class PersonService : IPersonService {

我创建了一个演示web应用程序,其中我尝试使用不包含svc文件的wcf服务。基本上,我尝试将路由添加到routetable,就像我们在asp.net mvc中添加的一样

我在这里引用了:

代码:

 [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class PersonService : IPersonService
    {
        [WebInvoke(UriTemplate = "", Method = "GET")]
        public void GetPerson()
        {
            string k = "a";
        }
    }

 [ServiceContract]
    public interface IPersonService
    {
        [OperationContract]
        void GetPerson();

    }

 public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            RouteTable.Routes.Add(new ServiceRoute("foo", new WebServiceHostFactory(), typeof(PersonService)));
        }
    }
Web.config:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

当我试图从浏览器调用GetPerson方法时,我发现未找到端点。


有人能帮我解决这个问题吗?

好的,我在Uritemplate中提供了我的方法名称,如下所示:

[WebInvoke(UriTemplate = "GetPerson", Method = "GET")]
        public void GetPerson()
        {
            string k = "a";
        }