0

I am working on a Restful WCF API. I figured out it would be nice to have one service contract for API related to Users (IUserService) and then for example another one for Posts that users add to the database (IPostService). This approach makes it easier to read the code , as well as to collaborate on the code, since several people can work on separate files.

However, this way, to make a requests I would have to call <url>/UserService.svc/user/123 to get a user and <url>/PostService.svc/post/456 to get a post.

Is this a viable solution , or should I have just one service for a case like this ? If yes, is there a way how to make it easier to collaborate and read the code ? Maybe with partial classes?

I don't have much experience with theses technologies and C# in general, so I will appreciate any help :)

Thanks.

Near
  • 391
  • 4
  • 16

1 Answers1

0

Your solution is definitely viable. And even more scalable if needed in the future than the partial classes solutions. By having the ability to split completly in multiple specialized services.

  • Is there any way to then route it more nicely , so that it would be possible for example request `/post/456` as well as `/user/123` ? Or is that purely a matter of server configuration? – Near Nov 08 '15 at 22:37
  • With WCF I would said no, I don't see something else than using URLRewrite module of IIS. But if you want to go for rest API, have you try ASP.NET Web API? It make lot of sense to use that if you don't care to have a SOAP/WSDL endpoint. – Jonathan Bavay Nov 08 '15 at 22:46
  • Ok thank you then. The thing is, this is a school project and we have to use WCF, but they let us choose if we want to use REST or SOAP. I find REST to be a much better choice for an application like this so that's what I decided to do with my group. But if I could choose, I wouldn't use WCF for an application like this. From what I've seen, WCF seems like it would fit better in a B2B scenario. – Near Nov 08 '15 at 22:49
  • @Near yes this is possible - see here: http://stackoverflow.com/questions/355165/how-to-remove-the-svc-extension-in-restful-wcf-service – tom redfern Nov 09 '15 at 14:45
  • it's request the IIS Module Rewriter. So server configuration and can't be integrated directly in the code. – Jonathan Bavay Nov 09 '15 at 17:07