从数据库填充WCF的路由表 [英] Populate routetable of wcf from database
问题描述
我想将端点动态添加到wcf的路由表中.
I want to add end points to route table of wcf dynamically.
代码:
[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("api", new WebServiceHostFactory(), typeof(PersonService)));
}
}
我在数据库表中保存了一些端点,如下所示:
/Customer/{Customer}/Address
/Customer/{Customer}/Address/{Address}
现在,我想填充将在IIS环境中托管并已在运行的wcf服务的路由表.
Now i want to populate routetable of my wcf service which will be hosted in IIS environment and is already running.
我在互联网上进行了大量搜索,但是找不到类似的内容,可以在其中将端点动态地添加到wcf的路由表中.
I have search alot on internet but couldnt find anything like such in which i can dyncamically add end points to routetable of wcf.
如果有人做过这样的事情,并且他们可以发布对我有帮助的代码/链接,我将非常感谢.
I will really appreciate if anybody have done anything like such and if they can post code/link that will help me.
谢谢:)
推荐答案
是否要将不同的端点路由到不同的方法?如果是这样,恐怕是不可能的.该方法由WebInvoke中定义的UriTemplate路由.如果要将不同的端点路由到不同的服务,建议您尝试检查 下面的链接是否满足您的要求.
Do you want to route different endpoints to different method? If so, I am afraid it is impossible. The method is routed by UriTemplate which is defined in WebInvoke. If you want to route different endpoints to different services, I suggest you try to check whether below link meets your requirement.
#使用路由组成WCF WebHttp服务
# Using Routes to Compose WCF WebHttp Services
https://博客. msdn.microsoft.com/endpoint/2010/01/25/using-routes-to-compose-wcf-webhttp-services/
这篇关于从数据库填充WCF的路由表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!