1

私は初心者ですWCFので、ご容赦ください。

サービスで新しいオブジェクトNullReferenceException occuredを作成しようとすると、なぜが取得されるのでしょうか。DateTimeWCF

これはコード行です:

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);

編集:

コールスタック:

ここに画像の説明を入力してください

4

1 に答える 1

3

WCFでDateTimeオブジェクトを使用することはできますか?

確かに。

スタックトレースは表示されませんが、回線DateTime fromDate = new DateTime(DateTime.Now.Ticks);が実際に失敗している可能性はありません。あるべきものは何もありませんnull。ただし、この行:

stagingEntityModel.User.FirstOrDefault(x => x.UserName == userName && x.Password == password);

間違いなく失敗する可能性があります。.Userあなたはそれがであることがわかると思いますnull。また、Visual Studioは、多くのことを実行しているように見えるので、失敗しているものではない他のステートメントにジャンプすることもわかると思います。

于 2012-12-27T12:07:47.943 に答える