期待xml resposnse时,OData查询选项如“$ select”无法正常工作

时间:2016-06-03 06:46:51

标签: asp.net asp.net-web-api

使用xml响应处理ODATA时遇到问题。在客户端获取内部服务器错误。我在服务器端调试代码没有出错,正确的响应对象正在生成并从服务器端返回,但在客户端生成“500内部服务器”错误。当我们要求json响应时,同样的事情完美地正常工作。当我点击没有“$ select”正确的xml响应的url时,我想在这里添加一件事。请在下面找到客户端和服务器端的代码。

function ConnectXML()
{
	var url = 'https://localhost:321/api/performance?$select=EmployeeID';
	$.ajax({     
   type     : "GET",
   url      : url,
   dataType: "xml",
   success  : function(msg){ alert('Success'); } ,
   error    : function(msg) { alert('Failed'); } 
}); 
}

   

public IQueryable<AppraisalsList> GetAppraisals()
    {
        try
        {
            string appraisalType = string.Empty;

            var allUrlKeyValues = ControllerContext.Request.GetQueryNameValuePairs();

            string type = allUrlKeyValues.SingleOrDefault(x => x.Key == "type").Value;

            if (!string.IsNullOrEmpty(type) && type.ToLower() != "regular" && type.ToLower() != "ondemand")
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid query params"));

            BusinessLogic.Appraisal.Appraisal appraisal = new BusinessLogic.Appraisal.Appraisal(new Settings() { Language = "en-US", UserID = 1, ConnectiongString = "Server=Kazim;Database=BEPMS_BEDemo;Integrated Security=SSPI; MultiSubnetFailover=True;multipleactiveresultsets=True;", AdminConnectiongString = "Server=Kazim;Database=BEPMS_AdminPortal;Integrated Security=SSPI; MultiSubnetFailover=True;multipleactiveresultsets=True;", ApplicationResourcePath = @"D:\Projects\BullseyeEvaluation Performance Management System\BullseyePerformance\Main Project\Source\Binaries", FiscalYearStart = 1, FiscalMonths = 12, DateFormat = "MM/dd/yyyy", NumberFormat = "123,456.78", DecimalPlaces = 2 });
            return appraisal.GetAppraisalsList(type).AsQueryable();
        }
        catch (Exception ex)
        {
            throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError, "Some error occured while processing your request"));
        }
    }

0 个答案:

没有答案