开发者

parameters in service route

开发者 https://www.devze.com 2023-02-06 20:35 出处:网络
Working on a WCF webhttp project and had a question on parameters in route composition. I have two services - Project service (that allows an user to add and view projects) and an Item service that

Working on a WCF webhttp project and had a question on parameters in route composition.

I have two services - Project service (that allows an user to add and view projects) and an Item service that allows the users to view items inside the project. There can be multiple items in a single project.

I would like to have urls of the form

localhost//projects//addproject

localhost//projects//{projectid}//item//additem

localhost//projects//{projectid}//item//getitem//{itemid}

I have twoservices ItemService and ProjectService. Itemservice has the methods additem and getitem Proj开发者_运维百科ectservice has the methods addproject

How do I declare these services in my global routes? I tried

RouteTable.Routes.Add(new ServiceRoute("projects/{projectid}/item", new WebServiceHostFactory(), typeof(ItemService))); This gives me an error

I can add all the code to ProjectService but I for maintainability of code I would like to have both ProjectService and ItemService


Just a suggestion:

  • you can create a controller called, say: "ProjectController".
  • add methods to it, that will call your service(s), say:

    • a. AddProject()
    • b. AddItem(int projectID)
    • c. GetItem(int projectID, int ItemID)

and you can call them almost the way you want:

localhost//project//AddProject

localhost//project//AddItem//{projectid}

localhost//project//GetItem//{projectid}//{itemid}

0

精彩评论

暂无评论...
验证码 换一张
取 消