1

Maybe this is a beginner question but I can't see the answer. So I'm build a web api that is going to consume 2 web services and the perfect case scenario would be the absence of mapping request and response objects. Is there anyway to share the same interface between the webapi and the 2 webservices?

This is in .net environment, webapi is being built in MVC.

whitecpt
  • 13
  • 6
  • maybe you can use that [difference between a web API and a web service?](https://stackoverflow.com/questions/19336347/what-is-the-difference-between-a-web-api-and-a-web-service) – Pouria Hemi Sep 12 '18 at 10:49
  • I don't know if you understood, i'm not trying to map from the request to the json, but as soon as I receive the object from the webservice it is required to map(?) – whitecpt Sep 12 '18 at 10:57
  • Hi @whitecpt, can you show your code? Or at least a sample of it? – toti08 Sep 12 '18 at 10:59
  • It's several classes, but I can explain an example. So in the webservice side I create a project where I hold my DataContract classes, one of it is called Home. Then in the WCF service project I create the ServiceContract with one method GetHome that returns the Home DataContract object. In the webapi side, first create a Home object. Somewhere inside one controller I need to call the previous webservice. I start by opening using 'using' and then what I would like is to do something like Home home = client.GetHome(); But this doesn't work since both Home objects have different sources – whitecpt Sep 12 '18 at 11:32
  • Look into automapper. If the properties are all the same it can auto map them in one line of code. Then you can use one class for both. – Wurd Sep 13 '18 at 09:32
  • That's what I was trying to avoid, because on complex objects I suppose it can be quite slow (?). But this is the way i'm going for. – whitecpt Sep 13 '18 at 14:04

0 Answers0