如何在 wcf 中使用路由 table 调用端点?
How to call endpoint using routing table in wcf?
我创建了 1 个演示 Web 应用程序,我在其中尝试使用不包含 svc 的 wcf 服务 file.Basically 我正在尝试向 routetable 添加路由,就像我们一样添加 asp.net mvc.
我参考了这里 :Reference
代码:
[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 not found。
有人可以帮我解决这个问题吗?
好的,我设法通过在 Uritemplate 中提供我的方法名称来解决它,如下所示:
[WebInvoke(UriTemplate = "GetPerson", Method = "GET")]
public void GetPerson()
{
string k = "a";
}
我创建了 1 个演示 Web 应用程序,我在其中尝试使用不包含 svc 的 wcf 服务 file.Basically 我正在尝试向 routetable 添加路由,就像我们一样添加 asp.net mvc.
我参考了这里 :Reference
代码:
[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 not found。
有人可以帮我解决这个问题吗?
好的,我设法通过在 Uritemplate 中提供我的方法名称来解决它,如下所示:
[WebInvoke(UriTemplate = "GetPerson", Method = "GET")]
public void GetPerson()
{
string k = "a";
}