My web service sits between a client and another web service. It converts the clients requests into another request to pass on to Sage 300 and returns the response back. Most of the time it is for pushing data in or updating it. I'm working on getting data
from the Sage system back to the client.
In the GetBalancesController I have: this function:
// GET api/<controller>
public string Get([FromQuery] string c = "", string s = "")
It is returning a string at the moment. When the client makes a request it will be in the form:
The parameters are not important. What is important is that when this URI is requested, my webservice constructs a call into Sage 300 to get what it needs. After a bit of work, it gets back the data I want and I alter it to what I need. If I serialise
the data to an XML string I get this:
That's great. But if I just return this to the Get function, it returns the XML as content rather than in the response body. How can I get the XML I've created from the return from Sage back to the client in the response body?
Member
24 Points
174 Posts
Return XML in response body
Jul 03, 2018 12:08 PM|AnyUserNameThatLetsMeIn|LINK
My web service sits between a client and another web service. It converts the clients requests into another request to pass on to Sage 300 and returns the response back. Most of the time it is for pushing data in or updating it. I'm working on getting data from the Sage system back to the client.
In the GetBalancesController I have: this function:
It is returning a string at the moment. When the client makes a request it will be in the form:
https://localhost:44316/api/GetBalances?s=DEVDAT&c=1200
The parameters are not important. What is important is that when this URI is requested, my webservice constructs a call into Sage 300 to get what it needs. After a bit of work, it gets back the data I want and I alter it to what I need. If I serialise the data to an XML string I get this:
That's great. But if I just return this to the Get function, it returns the XML as content rather than in the response body. How can I get the XML I've created from the return from Sage back to the client in the response body?
Thanks.
All-Star
52091 Points
23212 Posts
Re: Return XML in response body
Jul 03, 2018 01:18 PM|mgebhard|LINK
Don't manually serialize, just return a typed object from the action and let the framework handle the details.
Member
24 Points
174 Posts
Re: Return XML in response body
Jul 03, 2018 01:28 PM|AnyUserNameThatLetsMeIn|LINK
Haha :) I was just working through that before I saw your response. Seems like it is working now.