[英]How to call endpoint using routing table in wcf?
我已經創造了一種我試圖消耗不含SVC file.Basically我試圖路由添加到routetable就像我們在asp.net mvc的添加的WCF服務1個演示Web應用程序。
我從這里獲取了參考: 參考
代碼:
[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方法時,我找不到EndPoint 。
有人可以幫我嗎?
好的,我設法通過在Uritemplate中提供我的方法名稱來解決它,如下所示:
[WebInvoke(UriTemplate = "GetPerson", Method = "GET")]
public void GetPerson()
{
string k = "a";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.