Getting started with the Omniture APIs using Visual Studio 2010 (WCF)
If I had to pick one development platform as the most awkward for working with the Omniture web services it has to be Microsoft’s .NET. With Visual Studio 2005 it wasn’t too bad. You could simply leverage the WSE 3.0 extension and you were in business. But in Visual Studio 2010, WSE has been deprecated in favor of WCF, and unfortunately WCF doesn’t play nicely with the Password Digest authentication method used by the Omniture web services.
Microsoft declares… “B1102 WCF never emits Nonce and Created sub-elements of the UsernameToken.” http://msdn.microsoft.com/en-us/library/aa738565.aspx
This is a problem since the Omniture authentication requires both the Nonce and Created elements.
Luckily, talented Microsoft developers, like ASzego, have come to the rescue and have tweaked the WCF stack to solve the problem. See ASzego’s description of the problem and his solution here. http://blogs.msdn.com/b/aszego/archive/2010/06/24/usernametoken-profile-...
I’ve taken this code and packaged it up into a DLL file. I’ve also generated a second DLL file that contains the code produced from .NETs digestion of the Omniture WSDL. This code also needed a bit of tweaking which I won’t go into here. Both of these DLL files have been added to the code gallery here. http://developer.omniture.com/en_US/gallery/using-the-apis-with-wcf-dlls
What we have below is a getting started guide for putting together a quick VS2010 (C#) project that utilizes these two DLL files to make a successful request with the Omniture APIs.
Step 1: Create new Console application
Step 2: Copy the UsernameTokenLibrary.dll and OmnitureAPI.dll into the project. See DLLs.
Step 3: Add each dll file as a reference.
Step 4: Add “System.ServiceModel” as a reference under the “.NET” tab.
Step 5: Add the following code into the Main method…
OmnitureWebServicePortTypeClient client = OmnitureWebServicePortTypeClient.getClient("[api username]", "[api secret]", "https://api.omniture.com/admin/1.3/"); int tokenCount = client.CompanyGetTokenCount(); Console.WriteLine(tokenCount); Console.ReadLine(); //this is just to pause and observe the result when debugging
Step 6: Replace the first to arguments to the “getClient” method with your actual API username and API secret. Also, the third (endpoint) parameter may need to be adjusted based on which data center your account is tied to.
Step 7: Add the following “using” statements to the top of the file…
using System.ServiceModel; using System.ServiceModel.Description; using System.ServiceModel.Channels; using Microsoft.ServiceModel.Samples.CustomToken; using Adobe.OmnitureAPI;
Step 8: Run the application – observe the token count in the console window.
Finally, I must admit that I have very little experience with .NET and Visual Studio. The time I have spent is only due to the several desperate pleas I’ve seen for help in this area. If you have a better solution for using the Omniture APIs in VS 2010 I would love to hear it.
Please post your feedback.