Restful Web 服务路由
我正在开发一个 .net 4.0 wcf Restful 服务项目。作为项目的一部分,我创建了两个服务 1) OrderService 2)ProductService
此时我已在 Global.asax 中配置它们,如下所示:
RouteTable.Routes.Add(new ServiceRoute("products", new WebServiceHostFactory(),
typeof (ProductService)));
RouteTable.Routes.Add(new ServiceRoute("orders", new WebServiceHostFactory(),
typeof (OrderService)));
我可以使用以下 url 访问服务:
http://localhost/orders/123
http://localhost/products/456
但我的要求是我必须能够访问使用以下格式的 url 按特定顺序指定特定产品:
http://localhost/orders/{orderId}/products/{productId}
任何人都可以建议我应该使用什么路由来让两个不同的服务协同工作。
更新:ProductService中有一个方法接受两个参数
orderId和
productId
返回所需的产品
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 working together.
Update: There is method in the ProductService which accepts two parameters
orderId and
productId
to return the desired product
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
OrderService
(和相关服务合约)中,使用正确的UriTemplate
公开操作,如果它必须可通过路由到
orders
进行访问,则它不能位于 ProductService 中代码>订单服务。In your
OrderService
(and related service contract) expose operation with correctUriTemplate
It cannot be in ProductService if it must be accessible throgh
orders
routed toOrderService
.