Distributed Architecture: Part 1 - WCF Data Services ... A RESTful way of doing things

by Michael Hodgdon posted on July 7 2010 14:50

One of our strong practices here at Syndicated Methods is design and implementation of Service Oriented Architectures (SOA).  When people immediately hear SOA, they think SOAP and bloated contracts.  Yes, SOA boasts some grandiose goals with its standards, and with those goals comes a complex implementation. I have seen SOA make sense of many enterprises, and like any loyal developer ready to fight for their technology,  this mantra has always rubbed me the wrong way.   As of the release of .NET 4.0 however, and the rise of REST services, it has become quite clear that SOA isn’t the only way.  It has actually changed how I think of our practice.  So much so that I make sure to tell clients and folks that I talk to that our practice specializes in “Distributed Architectures”.  I have come to realize that we can take all of those lessons learned in SOA and apply them to any number of manners for exposing enterprise data in a distributed fashion applying the most suitable manner for clients.

After reading a recent article on WCF Data Services, it got me thinking about how to spread the word for such technologies.  Oh yeah, did you know Syndicated Methods has a blog!  So, I want to start a series on the Syndicated Blogs titled ”Distributed Architectures”.  The first candidate … you guessed it.  WCF Data Services.

WCF Data Services

There are certain scenarios where the development overhead associated with SOA is just not necessary.  For example, you have an analytics group that needs to have open access to a data store.  Or, you have an application that allows the user to shape and export data how they see fit.  Maybe you do a lot of prototyping and are looking for a turnkey solution for getting to your data. Such business problems have been solved by the Open Data Protocol (i.e. OData).  Those familiar with RESTful services will immediately understand.  The idea is to expose a repository of data over a standard pathing system, such as urls.  WCF Data Services takes these concepts and allows you to define a WCF Service (without the contracts of course) over an Entity Data Model.  You can expose your data in just a couple of easy steps.

Step 1 – Create a new Web Project on your local file system.  Any name for the site should do.

Step 2 – Next we need an Entity Data Model of the standard Sql Server Nothwind database.  You will want to create a new Entity Data Model pointed to a local instance of Northwind.  Go ahead and run all of the default configurations (make sure you place this in the App_Code section of the project).  You should end up with a Entity Data Model that looks similar to the following diagram:

 

Step 3 –Now it’s time create your service.  Create a new WCF Data Service in the root of the website. Now we are going to have to write a little bit of code here.  We only want to expose the Employees table for this exercise, so we need to tell the WCF Data Service to expose the Employee table.  In a real world implementation this could be done for all of the data tables / data sources required.  The code is rather trivial and is represented below:

Step 4 – Now for the fun stuff.  Let’s get your data!  You can easily pull your Employee data from the service by pointing DataServiceQuery at the endpoint.  Pretty neat!  No messy configurations, no service endpoints to deal with, and better yet you get your data in 4 or less easy steps.  I will let you play around with your services to get an idea of what it’s like to pull this data. Below is sample code for consuming the endpoint.


Before I close out this post, I want to just show you something that you may have missed.  I know that I missed it the first time through, so I want to just call it out.  WCF Data Services are employing the power of .net and WCF to allow you to address your data.  Users of the system only need to know the schema of the database.  We accessed the data by pointing to the following url:

http://localhost/WcfDataService.svc/Employees

This url basically says, use this service repository location, and show me all of the employees.  If we wanted the Customer data (assuming it was exposed in the WCF Data Service) we only need to access the following url:

http://localhost/WcfDataService.svc/Customers

And keeping true to the RESTful theme, if you want to narrow your data down you can pass a query along with this path like so:

http://localhost/WcfDataService.svc/Customers('ALFKI')/Orders?$filter=Freight gt 50

This will capture Customers with the id of ALFKI and will then filter those by getting freight values that are Greater Than 50.  Pretty neat.  Using these powerful data services allows you to get to a repository of data by simply "asking" for data in a standardized format.  If you are wondering how all of this data gets transferred, under the hood .NET will serialize this data in POX or JSON format.  The following screenshot verifies our transport data as depicted in Fiddler

 

As you can see the output is a standard ATOM Xml format.  Internet Explorer will conveniently display this as a RSS feed.  Anyone that is tasked with exposing data in a distributed fashion should definitely put this one in their toolbox!

{Happy Coding}

Tags: , , ,

A provisioning profile named embedded.mobileprovision already exists on this computer. Do you want to replace it?

by Stephen Dewitsky posted on July 2 2010 10:17

Ad hoc distribution of iPhone, and now iPad, applications can feel like a circus sideshow.  Developers come clambering out of the Provisioning Portal like its an undersized automobile to jump through flaming code signing hoops.  Generate a certificate, create an application id, add devices, create a provision, install them all and try not to get burned.  If you fail to do one step, or perform a step incorrectly, the application build results will usually guide you to the solution.  But what about when you do everything by the book and you still get an error?

The majority of my distribution issues usually sprout up when Apple releases a new version of the iPhone SDK.  This time it happened to be installing iPhone SDK 4.  After upgrading I needed to generate some Ad Hoc distributions.  Since these apps are only supposed to be targeted for iPhone devices, the "Base SDK" gets configured for "iPhone Device 4.0" and the "Targeted Device Family" is set to "iPhone". The only other parameter that needed changing was the "iPhone OS Deployment Target".  This app was not quite ready for "4.0" so I switched the value to "iPhone OS 3.1.3".

I configured three apps using the described values in exactly the same fashion.  The Ad Hoc distributions were generated and then zipped off to be installed.  To my dismay I received an email saying that one of the apps was incapable of being installed.  When the app is dragged into iTunes, nothing happens.  Successive attempts to drag the app into iTunes prompts this warning:

A provisioning profile named embedded.mobileprovision already exists on this computer.  Do you want to replace it?

Click the "Yes" button.  Nothing happens.  Click the "No" button.  Nothing happens.  At this point, I have no idea if I want to replace it.  I just want the app to sync with iTunes.  Time and time again I verify that all provisions are installed and configured properly.  Of course, none of which are named embedded.mobileprovision.  Search Google for embedded.mobileprovision and see what turns up.  Maybe a Twitter feed from a confused and frustrated developer.

There may be a multitude of reasons why this warning would appear when attempting an Ad Hoc installation but let me share with you the reason I was experiencing this issue.  Contrary to the message, the problem had nothing to do with an existing embedded.mobileprovision profile.  Some secret sleuthing lead me to believe that the issue originated when I choose a different "iPhone OS Deployment Target" in the project settings.  While I cannot prove this, I can at least show you some things to check manually before iAnarchy.

Every application has an Info.plist file that is created out of the box.  Find it in your application "Resources" group and it may look something like this:

 

Notice the dictionary entry "Application Requires iPhone Environment".  Notice the checkbox is clearly checked.  That makes sense.  We are developing an application using the iPhone SDK so it is only necessary that the application requires an iPhone environment.  Now open that same file as "Plain Text" to view the XML document which makes up this info dictionary.  Ours looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleDisplayName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIconFile</key>
    <string></string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSMainNibFile</key>
    <string>MainWindow</string>
    <key>UIStatusBarStyle</key>
    <string>UIStatusBarStyleBlackOpaque</string>
</dict>
</plist>

The pertinent key/value pair we are looking for is "LSRequiresIPhoneOS" and an XML node indicating <true/>.  999 times out of 1000 I would guess this is normal.  But on my 1000th attempt to build an app I see different a value:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleDisplayName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIconFile</key>
    <string></string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>${PRODUCT_NAME}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>LSRequiresIPhoneOS</key>
    <string>YES</string>
    <key>NSMainNibFile</key>
    <string>MainWindow</string>
    <key>UIStatusBarStyle</key>
    <string>UIStatusBarStyleBlackOpaque</string>
</dict>
</plist>

Notice how the value for <key>LSRequiresIPhoneOS</key> has been modified from a (bool)<true/> to a (string)<string>YES</string>.  How on earth this happened I cannot guarantee, but I can tell you that this is the reason "A provisioning profile named embedded.mobileprovision already exists on this computer".  If you take the time to manually replace the <string> node with a <true/> node you may be one step closer to a successful Ad Hoc distribution.

Tags: , , , ,

FBCDN image is not allowed in stream, How can this be?

by Stephen Dewitsky posted on June 22 2010 13:15

The phrase "FBCDN image is not allowed in stream" does not have much meaning to most of the natural world, but to a developer integrating with Facebook features this phrase is a nightmare.  Over the past year we have been developing iPhone apps that will process images in unique ways.  We thought it would be interesting to allow users to share these images with their friends on Facebook, if they have any friends.  The normal procedure is a two part process.  First, a user would upload the image to their very own photo gallery hosted on their Facebook profile.  When that is successful the user could then choose to publish a message to their stream which would include a link to this recently uploaded image.  It was fast and it was fun.

About two weeks ago I noticed that some previously published feeds, and any new feeds, were missing the shared photo.  Immediately I thought there must be a problem with the code.  Let me take a look.  HMMMMMMM.  Everything looks good, but why is the image missing?  Wow, I don't have much time to continue debugging this.  Let me check Facebook Developer Documentation.  Nothing here about missing images.

On the 17th of June 2010 the shock was felt. I was testing a new iPhone app we are working on for in20years.com.  The Facebook integration was complete and I attempted to publish a message to my Facebook profile using a Facebook Photo Gallery image.  The process came to a halt and the dialog read, "FBCDN image is not allowed in stream ..... You can see this because you are one of the developers of the app."  Ouch.  I could indeed see this message and yet I have no idea what it means.  Endless Google searches return nothing.

With shifting priorities in schedule we decided to let this go for the weekend.  Monday morning was a bit more informative.  Facebook Developer Forums erupted in outrage that all existing apps ceased to work due to this error. The official word came through an RSS feed reading:

Serving Images in Stream Stories
Jun 18, 2010 3:21pm

We no longer allow stream stories to contain images that are hosted on the fbcdn.net domain. The images associated with these URLs aren't always optimized for stream stories and occasionally resulted in errors, leading to a poor user experience. Make sure your stream attachments don't reference images with this domain. You should host the images locally.


So what does this mean?  Well it depends on your point of view.  It means Facebook does not have enough consideration for current applications using images in the fbcdn.net domain to grace the developers with a warning of this new policy.  I was experiencing problems for weeks before this statement was released.  It means that developers cannot rely on any implementation of a Facebook API component to behave the way they expect on a day to day basis.  It means that developers must find a way to host their own images if they plan on placing them in a Facebook Stream.  It means we must react with Ninja-like reflexes.

Tags: , , , ,

MobilePipes gets certified

by Michael Hodgdon posted on April 28 2010 17:32

MobilePipes grows up!

The MobilePipes team works hard on our product suite making sure that our customers are buying software that is top notch, bright and shiny, reliable, easy to use, stands the test of time, and, well you get the point!  We could assure all day long that our products meet this criteria but we took the extra steps to prove it. 

MobilePipes was officially certified by Microsoft this month as a certified product.  This means a lot for our marketing and sales material because we get to include the logo all over the place, but more importantly, it assures our customers that they are buying a quality product. 

For those familiar with the process we ensured that our code meets the Microsoft standard for .NET based Web Services, Managed Code, and Windows Server 2008 Hyper-V. 

 

 

Tags: , , , , , ,

Interop Types

by Michael Hodgdon posted on April 9 2010 03:52

Anyone that has ever consumed Interop assemblies from managed code has experienced some of the headaches with the old ways of coding Microsoft solutions.  Some of those bigger issues are dealing with DLL hell and having to deploy and rely on those exact assembly versions availability on the target system.  Add into the  equation many different target environments and you have a real mess on your hands.  The CLR team has added lots of great new features into .NET 4.0, one of those features is embedding Interop Types in your .net projects.  And ... it's really easy to do!

First lets paint a bit of a scenario.  You are working with a solution that must work with the Excel Interop classes.  You must first start by adding the assemblies as a reference into your project.  Now you code away and finish your solution.  Once you deploy you realize that two of your systems don't have the assemblies installed at all, a third has different versions of the assemblies, and the final system is happy.  1 out of 4 is pretty bad and I am sure your users will have the same reaction!  You could deploy those Interop assemblies along with your application but that is a bit messy as well given different deployment models and potential DCOM issues.

With Embedded Interop Types you can include your interfaces and functionality required for those Interop assemblies by simply checking off the embed on that assembly reference.  The following screen shot demonstrates.

Now, if you load up that application, and look at the loaded assemblies, you will find that no Interop assemblies are loaded and you are working completely within your managed code.  No need to rely on those target assemblies on the system.  You can read more at: Type Equivalence and Embedded Interop Types

{ Happy Coding }

Tags: , , ,

Virtualization under Windows Server 2008 Core

by Michael Hodgdon posted on February 28 2010 04:46

I was recently listening to a TWIT podcast that was discussing changes in technology over the past 10 years or so.  One area of innovation struck especially close to home for me ... Virtualization.  Virtualized environments have completely changed how I think about hosting development environments. Virtualization allows you to host multiple different environments on the same physical machines.  Depending on your hosting hardware you are going to use either VMWARE or Microsoft's Virtual PC / Virtual Server.

My role in Syndicated Methods requires lots of time researching new technologies.  Additionally, we have many developers that need to work on our solutions.  Virtualization has answered two major problems that have proved challenging to support these needs:

1) Minimizing hardware to support iPhone, ASP.NET, WAMP, and LAMP environments.  We can now have one or two machines that host all of these different development machines.

2) More importantly we don't waste time setting new developers up.  With a local running configuration of VMWARE, developers only need to copy a file over and they have everything they need to start coding. 

We run windows based servers in our local network.  With virtualization one of the things that has always troubled me is that CPU and RAM have gobbled up by a baseline Windows Server install.  The Windows Shell takes up a lot of resources to run services.  These are precious resources that essentially sit idle for a machine that is intended entirely for hosting virtualized environments.  Obviously other customers felt this way because Microsoft released Windows Server 2008 Core.  This special operating system is a Windows 2008 Server without the Windows Shell.  With the lightest foot print possible to host Windows, you can now install your Virtualization engine on top of 2008 Core and have more access to raw resources.  The Tech Republic Blogs have an excellent tutorial that walks you through the installed with Windows Virtual Server 2008.

Tags: , , ,

Essential WIndows Presentation Foundation

by Admin posted on January 24 2010 17:53

Microsoft has made the life of a .net developer trying to stay current extremely arduous!  Don't get me wrong, I am extremely happy that Microsoft has succeeded in expanding and adding great features to the .NET framework.  This is where short and concise literature on the vast subjects of .net become so important.  


I completed the "Essential Windows Presentation Foundation" by Chris Anderson, and I thank Chris for writing a book that fits this profile to a T.  Essential WPF gives you more than a brief overview but not so much content that you are reading a manual.  Chris is one of the Architect's of WPF and demonstrates his knowledge of the technology, and some history of the GUI for that matter, presented in a way that developers soak in.

WPF is groundbreaking and very different.  You win forms folks that have been waiting for the overhaul that ASP.NET gave to ASP will most certainly appreciate some of the changes in WPF.  Check it out, and I definitely recommend Essential WPF.  

 

































Tags: , , ,

My first Syndicated Post

by Admin posted on January 24 2010 17:45

It is about 1:48 here in Boston, and I am writing my first post to the Syndicated Methods blog!  I recently started with Syndicated Methods to help out with a lot of the technology needs of the organization.  Adding the ability for our developers to fling our thoughts about development into cyber space is a must, hence, welcome to the SyndicatedBlogs. 

I plan on updating this with all the cool and trendy stuff that we do here at Syndicated Methods.  You will also find whatever rant, praise, or rambling thoughts I might have on a given day.  I promise to keep them related to development ... well ... yeah I promise :). 

Hope you enjoy, and stay tuned ...

Tags: , , ,

Contact Us

We want to hear from you.  Our community is important to us and we want to make sure we give you the contact you want.  Please contact our team if you want to sent us feedback of any kind.  Enjoy reading!

RecentComments

Comment RSS