Я написал следующий код для возврата другого объекта Json, основанного на передаче пользователя JobId.
я хотел знать, было ли использование MemoryStream в функции ReturnPureJson вызывать какую-либо проблему, связанную с производительностью, в вызовах API WCF?
[WebInvoke(UriTemplate = "{jobId}", Method = "GET", ResponseFormat = WebMessageFormat.Json)]
public Stream GetJobData(Guid jobId)
{
object responseData = null;
//Code to fetch the proper Job Based on the JobId Passed
Job job = GetJobData(jobId);
if (job != null)
{
switch (job.JobType)
{
case JobType.UserData:
responseData = GetUserData(); //Returns a List<UserData> where Userdata is a class
break;
case Job.EJobType.ApplicationData:
responseData = GetApplicationData();//Returns a List<ApplicationData> where ApplicationData is a class
break;
//some more case statements to fetch appropriate response
}
}
return ReturnPureJson(responseData);
}
private Stream ReturnPureJson(dynamic responseModel)
{
string jsonClient = Json.Encode(responseModel);
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
return new MemoryStream(Encoding.UTF8.GetBytes(jsonClient));
}