Skip to main content

I have a smart object with two service object methods: one read method that returns a particular object and one list method that returns a collection of objects. The method that returns a single object has an "HttpResponseCode" return property; however, the method that returns a collection of objects does NOT have the "HttpResponseCode" return property.

 

I would like for the List method to populate an HttpResponseCode so that I can facilitate some error handling and I'm hoping someone might be able to offer some advice or point me in the right direction?

 

Here is the (similar) C# code for my ApiController class, in case that's helpful. The first/top HttpGet below is related to the problem child. While debugging in Visual Studio, I can see that the IHttpActionResult.StatusCode does actually equal OK (200)... however, the SmartObject never seems to recognize it. In K2Designer, the service object doesn't even offer a return property to bind to. The second/bottom HttpGet below seems to work fine - it DOES offer an "HttpResponseCode" property to bind to (shown in the attached screenshot).

 

/// <summary>

/// Retrieves a List of objects of type "SomeObject" for a given key

/// </summary>

/// <returns>List<SomeObject></returns>

nHttpGet]

tRoute("...")]

)ResponseType(typeof(List<SomeObject>))]

public IHttpActionResult GetSomeObjects(string key)

 

{

   var data = _dataService.GetSomeObjects(key);

   return Ok(data);

 }

 

/// <summary>

/// Retrieves info for a single SomeObject for a given key

/// </summary>

/// <returns>SomeObject</returns>

 

nHttpGet]

pRoute("..")]

.ResponseType(typeof(SomeObject))]

public IHttpActionResult GetSomeObject(string key)

 

{

   var data = _dataService.GetSomeObject(key);

   return Ok(data);

}

 

In the Service Instance configuration settings, I tried changing the "Add HTTP Response Header Property To Methods" service key to True, thinking that might help. It did not.

 

Any advice you can give would be appreciated.


10912i41A3E7700BF229F7.png

Hi,


 


I do not have much experience in developing my own service broker, but I suspect it is not possible to return a status code, then list out your results. How do you expect it to appear in your SmartObject? It is not possible to just display one HttpResponseCode, then list down all your results.


 


Either you attach the HttpResponseCode to your result set as another column, so when you list your results, all records will show the same HttpResponseCode, or you can do what the REST service broker is doing.


 


In the REST service broker, there is a particular method that will Read the response, and return 2 properties: HTTP Response Code, and the response. The response contains your entire list of records, all serialized into a json format. So to read those records, you will need to deserialize the response to break it down into the entire list.


Reply