0

I want to write some code to communicate with a RESTfull service which is created by another company. SO far I just integrated SOAP services into my own code and this worked pretty well with Service as a reference.

As I understood, this is not possible with REST Services. In my particular case, I would have to PUSH a XML file to the Service and I will recive an XML file back. With a referenced SOAP service, I wouldn't have to deal with the XML but with objects instead. Is there chance to obtain similair functionality with a REST service?

I looked into Web API but I am not sure if that is the right way.

Hopefully you get the point of my question.

Thank you very much for the help.

Sandman
  • 55
  • 7
  • https://stackoverflow.com/questions/9620278/how-do-i-make-calls-to-a-rest-api-using-c – Chetan Feb 05 '21 at 14:02
  • `this is not possible with REST Services`...it depends. Some vendors produce ready-made SDKs in various languages. Some might have published service definitions (e.g. Swagger contracts have a similar purpose to WSDLs) from which client code can be autogenerated. `ith a referenced SOAP service, I wouldn't have to deal with the XML but with objects instead`...and you still don't, necessarily - just generate the C# object, and then serialise it to XML (or JSON, or whatever the service accepts) when you send the request. In C#, libraries like HttpClient or RestSharp make this a lot easier for you. – ADyson Feb 05 '21 at 14:02
  • https://learn.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client – Chetan Feb 05 '21 at 14:03
  • `Web API` is irrelevant here I think - that the server-side, it's useful as a framework if you're writing your own API...it's nothing to do with how you make requests to someone else's API. – ADyson Feb 05 '21 at 14:04
  • https://code-maze.com/different-ways-consume-restful-api-csharp/ – Chetan Feb 05 '21 at 14:05
  • Thank you so far. THis vendor doesn't have any SDK unfortunately. THe fact that WebAPI is servier side is the reason why I didn't follow that path further I just hoped it would provide a tool to me. Seems like I will have to serialize the result XML into an object structure I need. – Sandman Feb 05 '21 at 14:29
  • 1
    Yes you can do that. Libraries like httpclient can handle serialisation automatically for you, when you pass in an object that you want to send. Similarly they can deserialise the response for you as well. You just have to create a class or classes which represent the structure you need. – ADyson Feb 05 '21 at 14:43
  • 1
    You might even be able to use a tool like https://xmltocsharp.azurewebsites.net/ to generate the classes from a sample of the XML data. – ADyson Feb 05 '21 at 14:48
  • Sounds interesting to use the HTTPClient for auto serialization. Would you have a link for further information or some god examples? The XML file I get back from the service is pretty big so this would really be helpful. Thank you – Sandman Feb 05 '21 at 16:08
  • Not specifically, no. But I imagine if you type "httpclient deserialize xml" into Google you'll get plenty of ideas. Not sure the size of the file is really relevant to the deserialisation process though. The tool I linked to above might help you with building the class structure. – ADyson Feb 05 '21 at 16:29
  • :) Of course, I did that already. THank you, this might already solve my issue with that topic. – Sandman Feb 05 '21 at 16:48

0 Answers0