C# 如何在wcf中使用路由表调用端点?
我创建了一个演示web应用程序,其中我尝试使用不包含svc文件的wcf服务。基本上,我尝试将路由添加到routetable,就像我们在asp.net mvc中添加的一样 我在这里引用了: 代码: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 {
[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";
}