我是新手,WCF
所以请多多包涵。
为什么我在我的服务中NullReferenceException occured
尝试创建一个新DateTime
对象时会得到一个。WCF
这是代码行:
DateTime fromDate = new DateTime(DateTime.Now.Ticks);
我尝试了各种方法,例如:
DateTime fromDate = new DateTime();
DateTime fromDate = DateTime.Now;
所有 3 行代码都给我一个NullReferenceException occured
错误。
截屏:
我可以在 中使用DateTime
对象WCF
吗?
编辑:
代码到该行:
public class CampaignSchedulePlacementService : ICampaignSchedulePlacementService
{
public PlacementAdvertRoutingAddressPairsResponce GetPlacementAdvertRoutingAddressPairs(string userName, string password, string routingAddressCode, int monthsBack, int monthsAhead)
{
return GetPlacementAdvertRoutingAddressPairsByFilters(userName, password, routingAddressCode, monthsBack, monthsAhead);
}
#region Methods
private PlacementAdvertRoutingAddressPairsResponce GetPlacementAdvertRoutingAddressPairsByFilters(string userName, string password, string routingAddressCode, int monthsBack, int monthsAhead)
{
PlacementAdvertRoutingAddressPairsResponce placementAdvertRoutingAddressPairsResponce = new PlacementAdvertRoutingAddressPairsResponce();
StagingEntityModel stagingEntityModel = null;
try
{
try
{
string connectionString = WebConfigurationManager.ConnectionStrings["Test"].ConnectionString;
stagingEntityModel = new StagingEntityModel(RMS.Common.Core.Public.GetEntityConnectionString(connectionString, "Data.EntityFramework.Model.StagingEntityModel"));
stagingEntityModel.Connection.Open();
}
catch (Exception ex)
{
placementAdvertRoutingAddressPairsResponce.Message = "Failed opening the connection :" + String.Format("{0}\r\n with an inner exception of {1}\r\nand a stack trace of {2}", ex.Message,
ex.InnerException != null ? ex.InnerException.Message : "",
ex.StackTrace);
return placementAdvertRoutingAddressPairsResponce;
}
User currentUser = stagingEntityModel.User.FirstOrDefault(x => x.UserName == userName && x.Password == password);
if (currentUser != null)
{
DateTime fromDate = new DateTime(DateTime.Now.Ticks); //.AddMonths(monthsBack * -1);
DateTime toDate = new DateTime(DateTime.Now.Ticks); //.AddMonths(monthsAhead);
编辑:
调用堆栈: