Tuesday, March 25, 2008

KISS
I was working on a little callout assembly recently and all went well until I had to hook into the customer's Java web service. I used WSDL.exe to generate a proxy class and was able to successfully instantiate the object and call into the Java web service (thanks Adam!), but I could not for the life of me get the XML right! I needed to pass in CRM account data, which comes into a postcallout in a very nice XML string, but then when I passed that XML string into the java web service it puked. I tried all kinds of fancy .NET methods to build the XML, for example:

System.Xml.XmlDocument mydoc = new System.Xml.XmlDocument();
mydoc.LoadXml("" );
mydoc.LoadXml("" );

XmlElement newElem = mydoc.CreateElement("account_request");
newElem.InnerXml = postImageEntityXml;
mydoc.DocumentElement.AppendChild( newElem );

XmlElement resp = mydoc.CreateElement("response");
newElem.InnerXml = "";mydoc.DocumentElement.AppendChild( resp );

with no joy.

Thankfully, a programmer at the customer lent a hand and as anyone who programs for a living knows, those extra eyes *really* come in handy! The end string that worked looked like this:
String myXML = "" +
"" +
postImageEntityXml +
"
";
mydoc.LoadXml(myXML);
XmlElement element = mydoc.DocumentElement;

Which without the formatting ended up at 3 lines. Nice. Keep It Sweet and Simple...isn't that what the acronym KISS stands for?? :)

No comments: