我正在试图弄清楚如何使用jQuery对ASMX Web服务进行JSONP调用.这些只是我已经阅读过的一些页面,但没有找到任何解决方案:
使用JQuery访问ASP.net webservice时出错 - JSONP
http://www.codeproject.com/Articles/43038/Accessing-Remote-ASP-NET-Web-Services-Using-JSONP
http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/
等等...
这是我的示例.NET Web方法:
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetEmployee(string employeeId, string callback)
{
// Get the employee object from the Factory.
Employee requestedEmployee = EmployeeFactory.GetEmployee(employeeId);
if(requestedEmployee != null)
{
// Return the padded JSON to the caller.
CrossDomainUtility.SendJsonP(callback, requestedEmployee.ToJson());
}
}
Run Code Online (Sandbox Code Playgroud)
这是SendJsonP():
public static void SendJsonP(string callback, string json)
{
// Clear any response that has already been prepared.
HttpContext.Current.Response.Clear();
// Set the content type …Run Code Online (Sandbox Code Playgroud) 我开始了解Unity容器和依赖注入.我很难理解我的对象模型应该是什么样子.
在我的例子中,我创建了一个非常简单的Employee类(我省略了构造函数,因为这是我所困惑的):
public class Employee
{
private int _id;
private string _name;
private DateTime _birthDate;
public int Id
{
get { return _id; }
}
public string Name
{
get { return _name; }
}
public DateTime BirthDate
{
get { return _birthDate; }
}
}
Run Code Online (Sandbox Code Playgroud)
此Employee对象应从数据库中获取其信息.这是一个填充数据库适配器,只是为了开发一个依赖:
public class DataAdapter
{
public DbParameter NewParameter(string name, object value)
{
return new OracleParameter(name, value);
}
public DataRow ExecuteDataRow(string command, CommandType commandType, List<DbParameter> parameters)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("ID"));
dt.Columns.Add(new …Run Code Online (Sandbox Code Playgroud)