开发者

Restful webservice routing

I am working on a .net 4.0 wcf restful service project. As part of the project i have created two services 1) OrderService 2)ProductService

At this moment i have configured them in Global.asax as follows:

RouteTable.Routes.Add(new ServiceRoute("products", new WebServiceHostFactory(),
                                                   typeof (ProductService)));
RouteTable.Routes.Add(new ServiceRoute("orders", new WebServiceHostFactory(),
                                                   typeof (OrderService)));

I can access the services using following urls:

    http://localhost/orders/123
    http://localhost/products/456

But my requirement is i must be able to access a particular product in a particular order using the url in the following format:

   http://localhost/orders/{orderId}/products/{productId}

Can anyone suggest what routing should i use to get the two different services wor开发者_StackOverflow社区king together.

Update: There is method in the ProductService which accepts two parameters

  1. orderId and

  2. productId

    to return the desired product


In your OrderService (and related service contract) expose operation with correct UriTemplate

public class OrderService : IOrderService
{
    [WebGet(UriTemplate = "{orderId}/products/{productId}")]
    public Product GetOrderProduct(int orderId, int productId)
    {
        ...
    }

}

It cannot be in ProductService if it must be accessible throgh orders routed to OrderService.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜