【发布时间】:2014-04-25 16:40:36
【问题描述】:
我有 ASP.NET 代码
public class OrderInformationResponse
{
public GetOrderLookupResponseType orderLookupResponse { get; set; }
}
[System.Web.Services.WebMethod]
public static OrderInformationResponse GetOrderInformation(string jobId, string userId, string jobDetails) {
OrderInformationResponse response = new OrderInformationResponse();
JobDetails jobDetailsEnum = (JobDetails)Enum.Parse(typeof(JobDetails), jobDetails);
response.orderLookupResponse = GetOrderLookup(jobId, userId);
return response;
}
我尝试从 jQuery 调用它:
$.ajax({
type: "POST",
url: "somePage.aspx/GetOrderInformation",
data: "{'jobId':" + jobId + ", " +
" 'userId':" + userId + ", " +
" 'jobDetails':" + jobDetails +
"}",
contentType: "application/json; charset=utf-8",
datatype: "json",
async: true,
cache: false,
success: function (msg) {
p_Func(msg); // This is a pointer to function.
}
});
GetOrderLookupResponseType的声明:
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.somewhere.uk/MessageContracts/OrderManagement/OrderInfo/2010/02")]
public partial class GetOrderLookupResponseType { ... }
我无法在客户端获得任何东西。在此之前,我试图从另一个标记为[WebMethod] 的方法返回GetOrderLookupResponseType 并且它有效,但是当我尝试将它放入新创建的OrderInformationResponse 时它停止工作。 (我打算用其他东西填充OrderInformationResponse,这就是为什么我没有使用有效的方法)。
【问题讨论】:
-
如果你真的调用了指定的 webmethod,你检查过开发者工具吗?你看到 http 响应码 200 了吗?
-
我现在检查了一下,我收到了响应 500。知道为什么吗?
-
您的代码中有一个未捕获的运行时异常。添加 try/catch 块并打印出异常。
-
我同意 Hamdi 解决方案。使用 try catch 块来拦截您的异常。当您有 200 个时,您将在开发人员工具中看到您的 json 作为您请求的响应。直到您看不到它。跨度>
-
@Hamid,原来是这样。
jobDetails是作为字符串发送的,但我没有在它周围加上任何引号。请回答问题,以便我接受您的回复。