SP2 brings some changes to the SData portal within SalesLogix. In conversation we say something like “there is a new Payload node and some enhancements such as batch loading and transaction tracking.” Where does this leave your 7.5.0 or 7.5.1 SData code? Some changes are needed and here is the short and sweet of it.
First there is a new payload node. Sorry, but I had to point it out. What this really means is that you cannot just go to the <entry> node anymore. You still need the <entry> node for the etag and some other things, but the actual data you want is actually two nodes down.
Also the URL has changed. Really a /-/ was added. Instead of:
'Dim result As String = client.DownloadString("http://localhost:3333/sdata/slx/dynamic/addresses")
you need this:
Dim result As String = client.DownloadString("http://localhost:3333/sdata/slx/dynamic/-/addresses")
That was easy.
If you look at the xml that you get back (in either case) you will see some namespaces defined at the top. Things like http, slx, sdata with a url at the end. These correspond to elements in your result. You need to have a XNamespace for each of these:
ReadOnly cf As XNamespace = XNamespace.Get("http://www.microsoft.com/schemas/rss/core/2005")
ReadOnly atom As XNamespace = XNamespace.Get("http://www.w3.org/2005/Atom")
ReadOnly slx As XNamespace = XNamespace.Get("http://schemas.sage.com/dynamic/2007")
ReadOnly sdata As XNamespace = XNamespace.Get("http://schemas.sage.com/sdata/2008/1")
ReadOnly xhttp As XNamespace = XNamespace.Get("http://schemas.sage.com/sdata/http/2008/1")
What this allow you to do is something like:
entry = (From Entry In doc.Descendants(atom + "entry") Select Entry).First()
etag = entry.Element(xhttp + "etag").Value
Now the code above is both LINQ and some xml manipulation. Basically the node called <entry> is within the atom namespace (because it is not specified) and I can get each one. I only want the first in this example because I am selecting an address by id (not shown).
Then I retrieve the etag using the xhttp namepace I declared above and the tag etag. This represents a hash of the entity and if this etag does not match when I PUT an update then I will receive an error telling me that the address I am trying to change has changed since I last got (GET) it.
I will use this etag later to place an if-match header when I try and update (PUT) later:
client.Headers.Add(HttpRequestHeader.ContentType, "application/atom+xml;type=entry")
client.Headers.Add(HttpRequestHeader.IfMatch, etag)
client.UploadString(putURI, "PUT", putPayload)
What else changed?
When you go to get the values for the actual address you need to get past the <entry> and into the <sdata:payload> and then you can get to your entity:
address = (From Entry In doc.Descendants(slx + "Address") Select Entry).First()
Again, LINQ and slx from the XNameSpace from above. In my example I am only getting one address, so I get the first one. (not shown).
The address will not contain the entry node or the payload node so you can add these back on:
Dim putPayload As String = "
" & address.ToString() & ""
Now there are 101 ways to get this done and this is one way. Give it a try and editing your existing code to work with the new SP2 changes should be a piece of cake.