Travelport / travelport-uapi-tutorial-c-sharp

The travelport-uapi-tutorial-c-sharp is a C# project for Universal API that will help you connect and code a standard Air availablity call and Hotel search, details, and booking flow.
35 stars 30 forks source link

Can i control the DateTime format sent to the UAPI ? (WCF serializer ) #203

Open dardar4 opened 4 years ago

dardar4 commented 4 years ago

Hi team. I'm facing a technical issue when implementing a solution to the UAPI using .net framework. just to be clear - we have a working application (again, in .net c#) that uses the UAPI and it is working well except one issue. We are using your WSDL (uAPI_WSDLschema_Release-V19.2.0.12) in order to create a service reference in visual studio 2017 this service reference is creating a reference.cs file with all the data members needed to call the UAPI service.

Our problem is with the AirMerchandisingFulfillment service. one of the elements in the requests is called CreateDate (which can be found at AirMerchandisingFulfillmentReq\OptionalServices\OptionalService\CreateDate) and it's of type DateTime

in the reference.cs file there is a class: public partial class OptionalService : object, System.ComponentModel.INotifyPropertyChanged

and one of its members is the CreateDate:

CreateDate

So far all is good. When I build the request I use the same values returned to me in the SeatMapRsp. I took a snapshot of the CreateDate member in the request

C SHARP REQ WITH GOOD VALUE

you can see that in the debug mode the CreateDate milliseconds part is "520"

BUT, and this is the issue, When I send this the UAPI it seems the .Net WCF serializer is trimming the last zero from the milliseconds, if possible and when I inspect the RAW data that is being transferred to the UAPI it seems like this:

RAW REQ WITH BAD VALUE

i.e. instead of sending "2020-04-13T09:59:22.520+03:00" it is sending "2020-04-13T09:59:22.52+03:00"

this is an issue since the UAPI has some kind of validation that check the format of the DateTime and this will cause a failure.

Have your team faced this issue before? maybe other developers also used .net to implement the UAPI and already resolved this issue?

plz advise ASAP there is also an open case in "MyTravelport" (CS0649249) but I thought this is a more technical place to address this issue

thanks

Amir

vivekjyotipramanik commented 4 years ago

Hi dardar4,

CreateDate is a optional attribute and even if you do not send this attribute, the request will work absolutely fine.

To get around the WCF Serialization issue, you can try using this workaround. Thanks.

https://stackoverflow.com/questions/3534525/force-xmlserializer-to-serialize-datetime-as-yyyy-mm-dd-hhmmss

dardar4 commented 4 years ago

Hi @vivekjyotipramanik thanks a lot for the quick reply.

How can I not send this attribute? in the SeatMapRsp I get an object "OptionalService" that has a member "CreateDate" with some value. Should I set it to NULL, since there is no real way to "reset" a DateTime in c# (as far as I know)?

also, regarding the link you posted - I've read it already in my search for an answer. I can definitely try it out but it requires me to change the classes your WSDL is creating. so even if the above solution will solve my problem - the next time we'll update the WSDL my solution will erase and someone (me or some future developer) will have to do it again (or go find a solution again ...)

thanks

Amir

vivekjyotipramanik commented 4 years ago

Hi dardar4,

Instead of just assigning the complete object, I would rather prefer to send only the required attributes of the objects, by assigning each field separately. In this way, the paylod will be lighter as well and In this way, you can only take the required fields and chose to ignore optional attributes. Please find below an example. Thanks.

public class Object{ public Object(string test1, string test2){ Test1 = test1; //required Test2 = test2; //optional } }

Object obj1 = new Object("Test1", "Test2");

Instead of,

Object obj2 = obj1

I would do,

Object ob2 = new Object{ Test1 = obj1.Test1 // Ignoring Test2 as optional };

dardar4 commented 4 years ago

Hi,

I understand what you trying to say but since I need to send the same object I'm getting in the SeatMapRsp (the entire OptionalService) it seems very inefficient to manually copy all elements in from 1 object to the same one, only to avoid a single DateTime member.

however, I think I found another solution. I noticed that there is also a boolean member that is called CreateDateSpecified and if I set it to false this member is being ignored and not transferred to the UAPI

Edit: Also setting the CreateDate to a new DateTime seems to be working something like that: foreach (var optionalService in airMerchandisingFulfillmentReq.OptionalServices?.OptionalService) { optionalService.CreateDate = new DateTime(); }

OR avoiding the CreateDate at all

foreach (var optionalService in airMerchandisingFulfillmentReq.OptionalServices?.OptionalService) { optionalService.CreateDateSpecified = false; }

the later one is more "elegant" in my opinion

thanks

Amir

vivekjyotipramanik commented 4 years ago

Hi dardar4,

I would prefer against copying complete object, as by copying only needed and required field, we can make the payload of request xml lighter and smaller.

As per opinion as well, the CreateDateSpecified=false is more elegant approach. Thanks.