【发布时间】:2019-03-01 10:19:07
【问题描述】:
我正在尝试在 asp.net 中编写 webservices Json。这段代码在我的本地电脑上运行。但它在服务器上不起作用。
[WebMethod(EnableSession = true)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 公共无效 GetMember() { HttpContext.Current.Response.Write(JsonConvert.SerializeObject(DALMember.GetAll())); }
[NullReferenceException:对象引用未设置为对象的实例。] DOAdverisingModule.AdsModule.context_PostRequestHandlerExecute(对象发送者,EventArgs e)+295 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +71
【问题讨论】:
-
NullReferenceException: Object reference not set to an instance of an object.逐步检查并找出哪个是空的。 -
我该怎么做?本地没有问题
-
嗯,它可能是
DALMember,因为错误上方的行指的是DALMember.GetAll()。因此,无论出于何种原因,该对象为空,所以.GetAll调用会抛出。 -
至于为什么它在本地而不是在服务器上工作,它们是否使用相同的数据源?
-
本地和服务器端都连接了sql server。