I am creating a RESTful web service using WCF. Consider the Service contract and implementation below:
[ServiceContract]
public interface IItemsSaleService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getItemDetails/{itemId}")]
SaleItem GetItemDetails(string itemId); //GET
}
//IMPLEMENTATION
async public SaleItem GetItemDetails(string itemId) //This wont work. It should be Task<SaleItem>
{
SaleItem item = await FindItem(itemId);
return item;
}
Assume that the FindItem is a thirdparty API method. Since I am using await, the method GetItemDetails has to be marked async and hence cannot return SaleItem. It has to return void or a Task which wont work for me as the method HAS to return SaleItem for the serializer to convert it to JSON and return it back to the client.
How do I fix this?
Another related question:
Method A calls Method B calls Method C - Method C uses await. Does this automatically require all the other methods to be async and hence always return Task<> or void?