我根据评论做出假设,您可以直接在浏览器中访问 Web 服务。
只是为了将您的自定义对象与配置隔离,您可以放置另一个服务,例如:
[WebMethod]
public static string GetServerTimeString()
{
return "Current Server Time: " + DateTime.Now.ToString();
}
从客户端 jQuery ajax 调用中调用它。如果这有效,那么它可能与您的对象特别相关,而不是服务器端的配置。否则,请继续查看服务器端配置跟踪。
编辑:一些示例代码:
[WebMethod(EnableSession = true)]
public Category[] GetCategoryList()
{
return GetCategories();
}
private Category[] GetCategories()
{
List<Category> category = new List<Category>();
CategoryCollection matchingCategories = CategoryList.GetCategoryList();
foreach (Category CategoryRow in matchingCategories)
{
category.Add(new Category(CategoryRow.CategoryId, CategoryRow.CategoryName));
}
return category.ToArray();
}
这是我发布复杂数据类型 JSON 值的示例
[WebMethod]
public static string SaveProcedureList(NewProcedureData procedureSaveData)
{
...do stuff here with my object
}
这实际上包括其中的两个对象数组...我的 NewProcedureData 类型是在一个列出这些对象的类中定义的。
编辑2:
以下是我在一个实例中处理复杂对象的方法:
function cptRow(cptCode, cptCodeText, rowIndex)
{
this.cptCode = cptCode;
this.cptCodeText = cptCodeText;
this.modifierList = new Array();
//...more stuff here you get the idea
}
/* set up the save object */
function procedureSet()
{
this.provider = $('select#providerSelect option:selected').val(); // currentPageDoctor;
this.patientIdtdb = currentPatientIdtdb;// a javascript object (string)
//...more object build stuff.
this.cptRows = Array();
for (i = 0; i < currentRowCount; i++)
{
if ($('.cptIcdLinkRow').eq(i).find('.cptEntryArea').val() != watermarkText)
{
this.cptRows[i] = new cptRow($('.cptIcdLinkRow').eq(i).find('.cptCode').val(), $('.cptIcdLinkRow').eq(i).find('.cptEntryArea').val(), i);//this is a javscript function that handles the array object
};
};
};
//here is and example where I wrap up the object
function SaveCurrentProcedures()
{
var currentSet = new procedureSet();
var procedureData = "";
var testData = { procedureSaveData: currentSet };
procedureData = JSON.stringify(testData);
SaveProceduresData(procedureData);
};
function SaveProceduresData(procedureSaveData)
{
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: procedureSaveData,
the rest of the ajax call...
});
};
注意!重要程序保存数据名称必须在客户端和服务器端完全匹配才能正常工作。EDIT3:更多代码示例:
using System;
using System.Collections.Generic;
using System.Web;
namespace MyNamespace.NewProcedure.BL
{
/// <summary>
/// lists of objects, names must match the JavaScript names
/// </summary>
public class NewProcedureData
{
private string _patientId = "";
private string _patientIdTdb = "";
private List<CptRows> _cptRows = new List<CptRows>();
public NewProcedureData()
{
}
public string PatientIdTdb
{
get { return _patientIdTdb; }
set { _patientIdTdb = value; }
}
public string PatientId
{
get { return _patientId; }
set { _patientId = value; }
}
public List<CptRows> CptRows = new List<CptRows>();
}
--------
using System;
using System.Collections.Generic;
using System.Web;
namespace MyNamespace.NewProcedure.BL
{
/// <summary>
/// lists of objects, names must match the JavaScript names
/// </summary>
public class CptRows
{
private string _cptCode = "";
private string _cptCodeText = "";
public CptRows()
{
}
public string CptCode
{
get { return _cptCode; }
set { _cptCode = value; }
}
public string CptCodeText
{
get { return _cptCodeText; }
set { _cptCodeText = value; }
}
}
}
希望这可以帮助。