我有一个使用ajax从javascript调用的C#webservice。 C#中的函数调用在6次左右没有任何理由重复,直到调用停止。我已经确定了导致它的原因,我不知道为什么。当返回的自定义对象(另一个自定义对象)的属性被分配给。
时,会发生这种情况我可以在任何地方的C#函数调用上放置一个断点,并且在webservice响应处理程序出现停顿错误之前它会被触发约6次。
网络服务电话:
function loadPeriodData(userID, loadHandler) {
var params = { userID: userID };
ajaxHelper.callMethod({
handler: loadPeriodDataHandler,
params: {
input: params
},
method: 'LoadPeriodData',
context: {
loadHandler: loadHandler
}
});
}
function loadPeriodDataHandler(response, textStatus, context) {
if (response.isError) {
errorHandler.logError(response.code, response.errorMessage);
} else {
context.loadHandler(response.results);
}
}
C#webservice函数及其调用的函数:
public interface IJobTime
{
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
LoadPeriodDataOutput LoadPeriodData(LoadPeriodDataInput input);
}
public class JobTime : IJobTime
{
public LoadPeriodDataOutput LoadPeriodData(LoadPeriodDataInput input)
{
LoadPeriodDataOutput output = new LoadPeriodDataOutput();
try
{
output.results = Profile.LoadPeriodData(input.userID);
output.isError = false;
}
catch (Exception ex)
{
output.isError = true;
output.errorMessage = ex.Message;
}
return output;
}
}
public class Profile
{
public static LoadPeriodDataOutputObject LoadPeriodData(Guid UserID)
{
LoadPeriodDataOutputObject results = new LoadPeriodDataOutputObject();
results.CurrentWeek = new ProfileSection();
return results;
}
}
违规行,如果' output.results ='部分被评论,没有反复调用:
output.results = Profile.LoadPeriodData(input.userID);
正在创建的对象类:
[DataContract]
public class LoadPeriodDataInput : JobTimeInput
{
[DataMember]
public Guid userID;
}
[DataContract]
public class LoadPeriodDataOutput : JobTimeOutput
{
[DataMember]
public LoadPeriodDataOutputObject results;
}
[DataContract]
public class LoadPeriodDataOutputObject
{
[DataMember]
public ProfileSection CurrentWeek;
}
[DataContract]
public class ProfileSection
{
[DataMember]
public DateTime StartDate;
[DataMember]
public DateTime EndDate;
[DataMember]
public float TotalHours = 0;
[DataMember]
public List<WorkedItem> WorkedJobs = new List<WorkedItem>();
[DataMember]
public List<WorkedItem> WorkedQuotes = new List<WorkedItem>();
[DataMember]
public string StartDateString
{
get
{
return StartDate.ToString("d MMM yyyy");
}
}
[DataMember]
public string EndDateString
{
get
{
return EndDate.ToString("d MMM yyyy");
}
}
}
[DataContract]
public class WorkedItem
{
[DataMember]
public string Name;
[DataMember]
public float Hours;
public WorkedItem(string name, float hours)
{
Name = name;
Hours = hours;
}
}
我排除了:
我认为这与自定义对象ProfileSection有关,因为如果LoadPeriodDataOutputObject.CurrentWeek是一个字符串而不是ProfileSection,我们没有问题。
任何线索?