Logging Serializable Objects

Here’s a handy method to log your object serialized as XML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//
public void LogObject(object obj)
{
	var msg = "";
	try
	{
		using (var w = new StringWriter())
		{
			var s = new XmlSerializer(obj.GetType());
			s.Serialize(w, obj);
			w.Flush();
			msg = w.ToString();
		}
	}
	catch (Exception e)
	{
		msg = e.Message.ToString();
	}
 
	msg = string.Format("{0}\n{1}", obj.GetType(), msg);
	Log.Debug(msg);
}
 
LogObject(msgHeader);
//

This is what my logger spit out

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
OTA_TravelItineraryReadNS2_2_0.MessageHeader
<?xml version="1.0" encoding="utf-16"?>
<MessageHeader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.ebxml.org/namespaces/messageHeader">
  <From>
    <PartyId>55555</PartyId>
  </From>
  <To>
    <PartyId>789789789</PartyId>
  </To>
  <CPAId>2WE2</CPAId>
  <ConversationId>130615-120130.2844</ConversationId>
  <Action>TravelItineraryReadLLSRQ</Action>
  <MessageData>
    <MessageId>mid:200051209-18808-23933@clientofsabre.com</MessageId>
  </MessageData>
</MessageHeader>

Frustration …

Frustrated with Sabre web services, grrrrr!

The version of the TravelItineraryRead web service I’m using is “2003A.TsabreXML1.15.1”. Yes, I know its a bit dated but it fits the needs .. until recently. I’m seeing more Rail segments come across and this version does not support them. So, I wanted to test the latest TravelItineraryRead version to see how or if Rail is supported. 

So I built my proxy classes using 
wsdl.exe  http://webservices.sabre.com/wsdl/tpfc/TravelItineraryReadLLS2.2.0RQ.wsdl  /namespace:OTA_TravelItineraryReadNS2_2_0
And setup my code to call the new service  

1
2
3
4
5
. . .
var serviceObj = new TravelItineraryReadService();
serviceObj.MessageHeaderValue = msgHeader;
serviceObj.Security = security;
TravelItineraryReadRS response = serviceObj.TravelItineraryReadRQ(req);

… and I get a null response. No errors or exceptions just a null response. So, I tweak my objects and try again – same null response. Make more changes – same null response. I go through several cycles of this and I’m stuck, I need help – another set of eyes to see what I’m doing wrong. (BTW, Sabre’s documentation on this web service is horrible. This is the root of my problem)

Next I contact Sabre’s web services support through email. This is my frustration … The email conversation goes on for 6 days. Maybe their support group is outside the USA or their policy it to email a maximum of a few times per day. Whichever the case, it is painfully slow dealing with them. The end result of this painfully slow email conversation is nothing, nada, zip, still getting null. The support group doesn’t have aqueduct documentation, no code samples, no code ownership and certainly no expertise.

 Long story shortened, this was my problem:

1
2
3
4
5
6
7
8
9
10
11
12
13
MessageHeader msgHeader = new MessageHeader();
 
// If the msgHeader.Action is not exactly 
// "TravelItineraryReadLLSRQ"
// your response will be null
msgHeader.Action = "TravelItineraryReadLLSRQ";
 
Service service = new Service();
service.Value = "TravelItineraryReadLLSRQ"; // THIS IS NOT USED!!!
service.type = "this object can be null";
msgHeader.Service = service; // THIS CAN BE NULL, IT'S NOT USED
 
. . .

Now I can finally start my research on Rail segments!!

There are not many “open” resources available for Sabre web services. I’ve written a lot of code to consume them…. contact me if you are stuck, maybe I can help.

Blogging C# Source in WordPress

1
2
3
4
5
6
7
8
9
10
11
12
13
using System;
namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine(Environment.NewLine + "Press Enter to exit.");
            Console.ReadLine();
        }
    }
}

New to WordPress so I fumbled around a bit figuring out a way to write about C#. I’m sure there are lots of ways to skin this cat but the first method I got working was with the WP-Syntax plugin. After installed, I copied my source from VisualStudio and stuffed it inside here :

<pre lang=”csharp” line=”1″> PASTE CODE HERE </pre>.