Guest User

Untitled

a guest
Jul 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public class SampleController : ApiController
  2. {
  3. [HttpGet]
  4. [Route("api/getobject")]
  5. public HttpResponseMessage GetByGSTNumber(string token, string key)
  6. {
  7. DataConnection connection = null; new DataConnection();//Set up COM reference
  8. DataObject dataObj = null;
  9. try
  10. {
  11. connection = new DataConnection();
  12. connection.login(token);
  13. dataObj = new DataObject(connection);
  14. Request.CreateResponse(HttpStatusCode.OK, dataObj);
  15. }
  16. catch (Exception ex)
  17. {
  18. return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
  19. }
  20. finally
  21. {
  22. if (connection != null) { Request.RegisterForDispose(connection); }
  23. if (dataObj != null) { Request.RegisterForDispose(dataObj); }
  24. }
  25. }
  26. }
  27.  
  28. public class DataObject : IDisposable
  29. {
  30. internal DataConnection dbConnection;
  31. internal dynamic _dataRecord;
  32. public string Key
  33. {
  34. get { return _dataRecord.KeyField.ToString(); }
  35. }
  36.  
  37. public string Property1
  38. {
  39. get { return _dataRecord.Property1Feild.ToString(); }
  40. }
  41.  
  42. public DataObject(DataConnection connection)
  43. {
  44. dbConnection = connection;
  45. }
  46.  
  47. public void OpenRecord(string key)
  48. {
  49. if (!_dataRecord.Seek(key))
  50. {
  51. throw new Exception("Record not found");
  52. }
  53.  
  54. }
  55.  
  56. #region IDisposable Support
  57. }
  58.  
  59. return Request.CreateResponse(HttpStatusCode.OK, dataObj);
  60. //Returns JSON even if specifying XML in request
  61.  
  62. return Request.CreateResponse(HttpStatusCode.OK, dataObj "application/xml");
  63. // returns <ExceptionMessage>Could not find a formatter matching the media type 'application/xml' that can write an instance of 'DataObject'.</ExceptionMessage>
Add Comment
Please, Sign In to add comment