WCF error parameter date equals "01/01/0001" - wcf

I am currently sending from SoapUI for my tests the following request:
<caja:GenerarObligacion>
<caja:Obligacion>
<obl:BenCheq>TALLERES ARROYO</obl:BenCheq>
<obl:CodMoneda>S/.</obl:CodMoneda>
<obl:CodProd>VM14</obl:CodProd>
<obl:CodRamo>AUTO</obl:CodRamo>
<obl:CodUsuario>ACSELP</obl:CodUsuario>
<obl:DptoEmi>000101</obl:DptoEmi>
<obl:FecFinVig>2024-02-28T12:00:01</obl:FecFinVig>
<obl:FecIniVig>2025-02-28T12:00:01</obl:FecIniVig>
<obl:FecMod>2026-07-17T13:02:05</obl:FecMod>
<obl:FecNotif>2026-07-17T13:02:05</obl:FecNotif>
<obl:FecOcurr>2025-01-28T08:41:53</obl:FecOcurr>
<obl:FecRecepDocPago>2025-01-28T00:00:00</obl:FecRecepDocPago>
<obl:IdePol>25000293961</obl:IdePol>
<obl:IdeSin>1500013900</obl:IdeSin>
<obl:IndCheque>S</obl:IndCheque>
<obl:ItemOblig>
<fac:BEDetalleObligacion>
<fac:CodCpto>DSCTOS</fac:CodCpto>
<fac:ItemDoc/>
<fac:FecFact>2025-01-28T00:00:00</fac:FecFact>
<fac:MtoCptoEgre>600.0</fac:MtoCptoEgre>
<fac:NroFact>444444444</fac:NroFact>
<fac:NumCpto>1</fac:NumCpto>
<fac:SerieFact>f045</fac:SerieFact>
<fac:TipoRegCompra>01</fac:TipoRegCompra>
</fac:BEDetalleObligacion>
<fac:BEDetalleObligacion>
<fac:CodCpto>ISLV</fac:CodCpto>
<fac:ItemDoc/>
<fac:FecFact>2025-01-28T00:00:00</fac:FecFact>
<fac:MtoCptoEgre>108.0</fac:MtoCptoEgre>
<fac:NroFact>444444444</fac:NroFact>
<fac:NumCpto>2</fac:NumCpto>
<fac:SerieFact>f045</fac:SerieFact>
<fac:TipoRegCompra>01</fac:TipoRegCompra>
</fac:BEDetalleObligacion>
</obl:ItemOblig>
<obl:MtoAprob>708.0</obl:MtoAprob>
<obl:NumAprob>18000493</obl:NumAprob>
<obl:NumPol>2500029396</obl:NumPol>
<obl:StsOblig>VAL</obl:StsOblig>
<obl:StsSin>ACT</obl:StsSin>
<obl:TasaCambio>1.0</obl:TasaCambio>
<obl:TipoAprob>P</obl:TipoAprob>
<obl:TipoBenef>TALR</obl:TipoBenef>
<obl:TipoDocPago>CHQ</obl:TipoDocPago>
</caja:Obligacion>
<caja:Tercero>
<ter:BETercero>
<ter:NumId>650606871</ter:NumId>
<ter:TipoId>J</ter:TipoId>
</ter:BETercero>
</caja:Tercero>
</caja:GenerarObligacion>
All the data arrives well except for the "FecFact" field, as seen in the request this field if it has a date but when arriving at the visual debug the following value "01/01/0001" is displayed:
In spite of sending a value to the FecFact field, it is set with the date that is displayed in the image "01/01/0001" as if the field were arriving null. This is the declaration of my entity.
[DataMember]
public String CodCtpo { get; set; }
[DataMember]
public DateTime FecFact { get; set; }
[DataMember] //IndIGV
public String IndnoGravado { get; set; }
[DataMember] //MtoCptoAprob
public Decimal MtoCptoEgre { get; set; }
[DataMember] // NumCpto - ?uso? NUMDETOBLIG
public Int32 NumCpto { get; set; }
[DataMember]
public String NroFact { get; set; }
[DataMember]
public String SerieFact { get; set; }
[DataMember]
public String TipoRegCompra { get; set; } //Funcional como OB
[DataMember]
public String CodSvcio { get; set; }

DateTime is initialized by default by DateTime.MinValue, which is actually 1/1/0001 12:00:00 AM exactly same as what you are getting.
You should declare nullable field if want null Date like:
DateTime? dt = null;
OR
Compare DateTime variables to DateTime.MinValue & set corresponding value in database query as null or in UI variable as null.

According to your description, I have restored your problem successfully,
The only thing you need to do is try to assign the NameSpace attribute to the DataContract Class.
[DataContract(Namespace ="mydomain")]
public class Product
{
[DataMember]
public int ID { get; set; }
[DataMember]
public DateTime dateTime { get; set; }
}
I hope this information is useful.

Related

Adding [ResultColumn] to Database.tt in PetaPoco

I am an avid user of PetaPoco. Is there any way to tweak the Database.tt (for generation of POCO's) to specify a ResultColumn in a specific table?
TIA
Currently, the Database.tt states:
// Tweak Schema
tables["tablename"].Ignore = true; // To ignore a table
tables["tablename"].ClassName = "newname"; // To change the class name of a table
tables["tablename"]["columnname"].Ignore = true; // To ignore a column
tables["tablename"]["columnname"].PropertyName="newname"; // To change the property name of a column
tables["tablename"]["columnname"].PropertyType="bool"; // To change the property type of a column
I do not know how to change the template, other then these instructions (which work very well). I was hoping for a similar statement that could produce a POCO like:
[TableName("phoenix.view_medical_records")]
[ExplicitColumns]
public partial class view_medical_records
{
[Column] public string lastname { get; set; }
[Column] public string firstname { get; set; }
[Column] public string birthdate { get; set; }
[Column] public int? chart_number { get; set; }
[ResultColumn] public DateTime tservice { get; set; }
[Column] public string status { get; set; }
[ResultColumn] public DateTime tcompleted { get; set; }
[Column] public string procedure_description { get; set; }
[Column] public string description { get; set; }
[Column] public string provider { get; set; }
}
Note: the [ResultColumn] attribute being automatically supplied?!
Thanks.
As per my comment on the question, PetaPoco doesn't support result columns via the T4 generator files. However, a workaround would be to ignore the columns
tables["phoenix.view_medical_records"]["tservice"].Ignore = true;
tables["phoenix.view_medical_records"]["tcompleted"].Ignore = true;
And, supply partial classes for the generated one which supply the columns.
public partial Poco1
{
// Generated by PP
}
public partial Poco1
{
// Supplied by the developer (Must be in same namespace)
[ResultColumn] public DateTime tservice { get; set; }
[ResultColumn] public DateTime tcompleted { get; set; }
}

Format list elements in viewmodel

In my viewmodel I have SubscriptionExpires formatted as below
public class IndexViewModel
{
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dddd d MMMM yyyy}")]
public DateTime? SubscriptionExpires { get; set; }
public IEnumerable<Device> Devices { get; set; }
}
Device also includes a date property
public partial class Device
{
[Key]
public int DeviceId { get; set; }
public string UserId { get; set; }
public virtual ApplicationUser User { get; set; }
public string DeviceName { get; set; }
public DateTime UnlockedTo { get; set; }
}
Is there any way of setting the date format for UnlockedTo in IndexViewModel or must formatting for this property be done in the view?
View should be responsible for formatting and showing data. Model is responsible just to deliver those data.

Saving Data using Entity Framework Code First

I am using ASP.NET MVC Razor Entity Framework Code First C#
Class - A
public class Om_Category
{
[Key]
public int CategoryID { get; set; }
public String CategoryName { get; set; }
public String CategorySanitized { get; set; }
public Boolean IsActive { get; set; }
public DateTime CreationDate { get; set; }
}
Class - B
public class Om_CategorySkills
{
[Key]
public Int32 SkillID { get; set; }
public String Skill { get; set; }
public String SkillSanitized { get; set; }
public DateTime CreationDate { get; set; }
public Boolean IsActive { get; set; }
public Om_Category Category { get; set; }
}
When I try to create the record for table Om_CategorySkills. It says
cannot save the duplicate value in Om_Category table.
This is happening because I am sending the Om_Category class object in Om_CategorySkills class object because there are some fields in Om_Category class that are mandatory.
So I am passing the Om_Category class object also in Om_CategorySkills class object. Is there any way to fix this issue ?
Your navigation properties doesn't seem to be right.. Can you try (I didn't test),
public class Om_Category
{
[Key]
public int CategoryID { get; set; }
public String CategoryName { get; set; }
public String CategorySanitized { get; set; }
public Boolean IsActive { get; set; }
public DateTime CreationDate { get; set; }
public virtual Om_CategorySkills CategorySkills{ get; set; }
}
public class Om_CategorySkills
{
[Key]
public Int32 SkillID { get; set; }
public String Skill { get; set; }
public String SkillSanitized { get; set; }
public DateTime CreationDate { get; set; }
public Boolean IsActive { get; set; }
public int CategoryID {get;set;}
public virtual Om_Category Category { get; set; }
}
I see that your Om_CategorySkills object is lacking an Int32 Om_CategoryId property to be used as foreign key. I would also add a virtual modifier to the navigation property Category, in order to allow for lazy loading.
I think that it may be the case that the category object in your new/edited skill is already in the database, but was not the one retrieved by the context, so the context believes you are trying to save a new category with the Id of an existing one.
You should not try to save a skill object with a category object with no changes. Otherwise, the category object should be the one attached to the context.

Joins in Entity Framework 5

I have two classes in my model
[Table("tblPackages")]
public class Packages
{
public int Id { get; set; }
[Required]
[Display(Name = "Package Type")]
public int TypeId { get; set; }
[Display(Name = "No of SMS")]
public int AllowedSMS { get; set; }
[Display(Name = "Time Span in Days")]
public int? TimeSpan { get; set; }
public decimal Price { get; set; }
}
[Table("tblPackageTypes")]
public class PackageTypes
{
public int Id { get; set; }
public string Name { get; set; }
public string Details { get; set; }
public DateTime DueDate { get; set; }
}
and the table is same. now i need to get all from class Packages and just Name from class PackageTypes. How can i do by just using Entity Framework
Add a PackageTypes navigation property to your Packages class and access it by name:
[Table("tblPackages")]
public class Packages
{
public int Id { get; set; }
[Required]
[Display(Name = "Package Type")]
public int PackageTypesId { get; set; }
public PackageTypes PackageTypes { get; get; }
[Display(Name = "No of SMS")]
public int AllowedSMS { get; set; }
[Display(Name = "Time Span in Days")]
public int? TimeSpan { get; set; }
public decimal Price { get; set; }
}
By convention, Entity Framework will match the PackageTypesId and PackageTypes properties based on the naming (although you can use different names if you configure it to do so, but that's a more advanced topic).
Now you can access the Name directly from your Packages objects:
myPackage.PackageTypes.Name
Also, you might want to think about your classes in the singular, not the plural. The class represents a single Package, not the entire collection. Same with the PackageType. It makes your code more understandable:
Package myPackage = new Package();
myPackage.PackageType.Name
Only use plural if your class truly represents the entire collection and not a single item.
Use a navigation property, you will need a FK relationship between Packages and PackageTypes:
[Table("tblPackages")]
public class Packages
{
public int Id { get; set; }
[Required]
[Display(Name = "Package Type")]
public int TypeId { get; set; }
[Display(Name = "No of SMS")]
public int AllowedSMS { get; set; }
[Display(Name = "Time Span in Days")]
public int? TimeSpan { get; set; }
public decimal Price { get; set; }
public int PackageTypesId {get;set;}
public virtual PackageTypes {get;set;}
}
[Table("tblPackageTypes")]
public class PackageTypes
{
public int Id { get; set; }
public string Name { get; set; }
public string Details { get; set; }
public DateTime DueDate { get; set; }
public ICollection<Packages> {get;set;}
}
Like the previous answer states you need a navigation property. From your code I assume TypeId is FK to Id in PackageTypes. If this is so, simply create a property named Type of the type PackageType. When EF finds a navigation property to another entity it tries to find the property with the FK by appending the suffix Id or _Id.
If you on the other want a true composite object joining in fields from several tables you should use a view for this!
Regards
HÃ¥kan

MVC4 Mailgun delivered webhook

I'm having an issue making use of the Mailgun delivered webhook, it can be found here: http://documentation.mailgun.net/user_manual.html#events-webhooks, look for "Delivered Event Webhook"
I am unable to reference Request.Params["Message-Id"] unless I modify the app's requestValidationMode to 2.0
I do get the potentially unsafe error when trying to reference this field without requestValidationMode = 2.0. The contents of the field are: <20130203200110.12345.12345#mydomain.mailgun.org>. I've also tried to declare a model to take advantage of auto model binding. My model looks like this:
public class MailgunDeliveredEvent
{
public string Id { get; set; }
public string Event { get; set; }
public string Recipient { get; set; }
public string Domain { get; set; }
[AllowHtml]
[JsonProperty(PropertyName="Message-Id")]
public object MessageId { get; set; }
public int Timestamp { get; set; }
public string Token { get; set; }
public string Signature { get; set; }
}
When I attempt to reference the MessageId field it returns null. I've tried to add
[Bind(Exclude="message-headers")]
As I'm not interested in that field.
In the Controller, I've set
[ValidateInput(false)]
I can't seem to get the Message-Id field back. Any help?
I seem to have got it working, in case anyone runs into the same issue...
I added a new model binder as referenced here:
Asp.Net MVC 2 - Bind a model's property to a different named value
I then changed my model like so:
[ModelBinder(typeof(DefaultModelBinderEx))]
public class MailgunDeliveredEvent
{
public string Id { get; set; }
public string Event { get; set; }
public string Recipient { get; set; }
public string Domain { get; set; }
[BindAlias("Message-Id")]
public string MessageId { get; set; }
public int Timestamp { get; set; }
public string Token { get; set; }
public string Signature { get; set; }
}
And all seems to work, I didn't need to call
[ValidateInput(false)]
on the controller either.
Hope that helps someone.