How to consume a WCF service from Perl with SOAP::Lite

Posted by adamjh on Jul 23rd, 2007

Due to the outdated state of Perl's only SOAP library and less-than-stellar documentation on Windows Communication Foundation web service interoperability, getting a Perl script to consume a WCF service sent me on a debugging adventure accompanied by a scavenger hunt for information scattered across the web.

Below are the tweaks that must be made to a new WCF service created using the "WCF Service Library" project template in Visual Studio 2008 Beta 1 ("Orcas") and an example of a how to call the service from a SOAP::Lite client script:

Step 1. Change the service endpoint binding from the default wsHttpBinding to basicHttpBinding:

    <endpoint address ="" binding="basicHttpBinding" contract="Service1.IService1" />

Step 2. Change the data contract format to RPC:

    [ServiceContract]
    [DataContractFormat(Style=OperationFormatStyle.Rpc)]
    public interface IService1
    {

Step 3. Specify an on_action() method in the SOAP::Lite client to override the default Namespace#Action with the format WCF expects:

$data = SOAP::Lite
  -> uri('http://tempuri.org/')
  -> proxy('http://localhost:8080/IService1')
  -> on_action(sub{sprintf '%sIService1/%s', @_})
  -> GetData(SOAP::Data->name('intParam' => 5))->result;

Note: If you decide to do this, you should understand the implications of changing the service endpoint binding and the data contract format.  Supporting information is available somewhere in the bowels of MSDN.

Update [Nov 5 2007]: I ran into new problems when moving from SOAP::Lite 0.55 (the highest supported in ActivePerl on Windows) to SOAP::Lite 0.69 (the latest version as of now, and running on Linux).  It seems SOAP::Lite evolved from the SOAP 1999 (1.1) to 2001 (1.2) schema, and somewhere in the mix, new conflicts arose with WCF interoperability.  After a few hours of horrid tracing and hacking, I've decided to ditch Perl and SOAP altogether for Ruby and REST.  Welcome, Adam, to the year 2007.

One solution to Wordpress code-snippet formatting problems

Posted by jeff on Jul 22nd, 2007

As Adam sat down to write the previous post on Linq, his frustration level was rising fast. What was wrong? It turns out the WordPress 2.2.1 visual editor completely mangles colorized source code pasted from Visual Studio. As you flip between “Visual” and “Code” editor modes, your code snippet begins to lose all of its precious formatting.

For example, this:

    class Program {
        static void Main() {
            /* do something */
        }
    }

... ends up very quickly looking like this:

class Program {static void Main() {/* do something */ }}

The real problem here is in the way that the visual editor interprets pasted text. It makes assumptions that would be good for a lot of things -- say, pasting text from an email. The assumptions are pretty bad for source code, unfortunately.

Nevertheless, I wanted to and find some workaround, since we're going to be pasting a lot of code snippets as time goes on. The first thing we noticed from reading posts from frustrated bloggers is that if you avoid the Visual editor altogether, it won't mangle your post's formatting. Some people create special accounts with the Visual editor defaulted off, and use those to post code-related entries. This solution is kind of annoying, since the Visual mode is a nicer interface in general.

Some bloggers have posted hacks to the Wordpress editor into being more friendly. Other people have created some plugins to help with this problem. This post explains part of the needed conversion process to allow special symbols like < and > to appear correctly. My experience was that most of the conversion is dealt with correctly within code tag, and that I just needed to add a little extra finesse. Adam tried the Preserve Code Formatting plugin, Windows Live Writer, and CodeHighlighterPlugin. He had varying success, but none were compatible with the Visual editor, and the code colorizing was dependent on the plugin's language support. So, I came up with a parallel solution:

<code> tags: The Visual editor is less disruptive on text within <code> tags. This makes sense, since the code tag is supposed to allow you to add simple plaintext. Unfortunately, it still removes some line breaks, and also removes some consecutive spaces after you paste code even while in the Code editor. Further, pasting directly into a <code> tag from the visual editor causes similar problems.

The solution: After playing around with several ways to encode code snippets as HTML, and testing them inside of <code> blocks, I found an encoding that seems to survive the wrath of the Visual editor. Here's what I did: Convert all spaces to nonbreaking spaces, i.e. . Next, convert all line breaks to <span> tags with attribute style=display:block; finally, for prettier code, wrap all colorized text in a <span> with the appropriate color specified.

Of course this would be very annoying if you had to do it yourself every time you wanted to paste a code snippet. So I packaged it all up into a C# project, which you can download here. Alternately, you can just get the executable here (Requires .NET Framework 2.0).

The program's pretty self-explanatory. Here's a screenshot:

Code Formatter Screenshot

Update regarding Firefox: Line indentation doesn't work properly when you switch to the Visual mode after pasting the code generated by this tool.  Things stay formatted correctly in when editing within IE7.

Data Access Layer: To LINQ or not to LINQ

Posted by adamjh on Jul 21st, 2007

Over the last several days, our progress meter has leveled off a bit as we've begun to take a step back from rapid prototyping efforts to spend some time thinking through the ways in which components of our system will communicate with each other.

One specific technology, LINQ to SQL (formerly "DLink" and almost certainly to be renamed again before it is released early next year), has particular potential as a drop-in replacement for the traditional data access layer.  DotNetSlackers has a pretty decent introduction, and Kris Vandermotten shares some thoughts on LINQ's implications on the DAL here and here.  He writes:

There is no doubt that Linq to SQL will have an enormous impact on the way we write data access layers. I wouldn’t be surprised to find out that the impact is so profound, that we might even have to reconsider the very nature of a data access layer. In fact, what is a data access layer (DAL) anyway?

Kris's second post concludes that the LINQ/SqlMetal-generated classes might serve as a DAL in and of themselves.  After reading it, I started wondering if/how this might apply to the data access layer we had begun to hack together earlier in the morning.  Jeff and I spent several hours reading, whiteboarding, and discussing whether or not LINQ was ready for "prime time", and if/how we would leverage it in what we're building.

While the idea of not having to design, implement, and maintain a data access layer designed around the needs of our specific system is tempting, a few questions come to mind:

  1. Can LINQ replace the object/relational mapping functionality performed by, and abstraction provided by, the traditional data access layer?
  2. Can instances of the LINQ/SqlMetal-generated easily be passed between components at different tiers?
  3. How does LINQ fit with scaling mechanisms that involve indirection such as data caching and partitioning?
  4. Is there sufficient support for all of the SQL features we're likely to use?
  5. Is it sufficiently performant? (promising early results)

Let's look at question #1.  Traditionally, all of the code that handles queries might have been pushed down into a set of data access methods, libraries, or even services that return data through a set of shared classes or interfaces.  In a simple example, to retrieve information about a user given her email address, I might call a GetUser() method that takes in an email address and returns a User object.  As time progresses, I might realize there is a better way to design my data access layer than exposing hundreds of GetUser()-like methods, and consolidate them by adding more flexible parameters or even by designing a mini-query language myself.  All this data access infrastructure, serving primarily to translate between relational data returned by SQL queries and object data modeled as a set of classes, is time-consuming, and is where I believe LINQ brings significant value.

For example, suppose the component I am working on needs to retrieve information about currently logged-in users.  Using LINQ as a data access mechanism, I could simply code:

        Table<User> users = db.GetTable<User>();

        var q = from u in users
                where u.LoggedIn == true
                select u;
        
        List<User> loggedInUsers = new List<User>(q);

Now, suppose I decide I want to display all the photos of all the currently logged-in users.  Again, using LINQ, with no design/implementation/management overhead around this specific retrieval which joins user and photo data that happens to reside in different tables, I could simply tack-on the following to the above code:

        foreach (var user in loggedInUsers)
        {
            foreach (var photo in user.Photos)
            {
                DisplayPhoto(photo.Data);
            }
        }

In cases where certain specific queries, even as expressed in C#/.Net syntax, are complex and might be reused across the codebase, it still might make sense to extract them out (in their LINQ form).  But the majority overhead of designing, implementing, and maintaining a traditional data access layer is still effectively replaced by the value of LINQ.  So, to sum up my thoughts around question #1, I'd at least say that I'd be willing to explore moving away from the traditional notion of abstracting away queries into a data access "layer", given the value that the LINQ constructs bring to the language/framework.

While question #1 was mostly about buying into vision/value, questions #2-5 are where the rubber hits the road, and are where limitations begin to arise that make us question whether or not LINQ version 1 will meet our needs, as follows:

First, if we are no longer constructing our own set of classes to model data and data retrieval methods to instantiate/populate them, we need to be able to pass LINQ and SqlMetal-generated objects around our n-tier application.  The DataContext is not serializable nor intended to be passed between tiers, and while there is an attach mechanism, support in general for these n-tier scenarios seems to be limited.  Showstopper.

Second, I haven't been able to dig up any strategies or support for introducing indirection into LINQ queries.  If our data is partitioned across many databases, or we need to introduce a cache, I'm unsure how to do this other than wrapping LINQ with well, a data access layer!

Third, I can't seem to find any answers to whether or not LINQ will support some of the newer SQL features like Spatial types/queries, again implying the need for some sort of parallel data access mechanism.

So, to wrap this post up... after roughly a day of investigation, it's safe to say that we've come to the conclusion that while LINQ is a promising technology, and could potentially replace much of the overhead in designing, implementing, and maintaining a data access layer in the future, it's no silver bullet today.  We'll likely incorporate it into our system in some capacity (i.e. as syntactic sugar for querying SQL), but it will likely remain abstracted by a set of data access mechanisms that will still be required for any data that is likely to be cached, partitioned, or accessed by multiple components/tiers now or in the future.

Why?

Posted by jeff on Jul 18th, 2007

About me: I sleep on a futon -- in my office -- somewhere in Los Angeles. I have no car, at least not within 2000 miles. My current income is zero. I have maybe three friends in a 30-mile radius. The decision to start something put me into this situation, and it also meant passing on several jobs, and breaking directly out of grad research at college.

Like a lot of people, I have ideas about technology. What it could do and should do versus what it does do. This gap creates a sort of urge to jump in and help fix the situation. With positive polling feedback from friends and family, it became clear there was a small influx of ideas that could be tied together to help solve a real problem. And now we will spend the next several months validating a concept and helping to solve this problem. The space is fascinating, but really, it’s less about this exact problem and more about that urge to jump in. That said, we didn’t have to drop everything and start this, there were other options. I could do some of this at a university, but it’s more satisfying and challenging to create for a broader audience. We could start this after-hours, but the probability of success is lower, and we need every ounce of that already-low-probability to have a reasonable expectation of success. I considered some jobs with a high innovation quotient, where they are really exploring new waters. But even in the best cases, personal impact would be shielded, and I presume it’s somewhat more exciting to be a captain than a crewmate on any expedition.

BarCamp geek dinner 7/17Our status is incrementally nudging up the code ticker (generally speaking not by just hitting ‘enter’ all day), and taking periodic breaks from that to draft-architect parts of our system. We also attended our first business-related-social-gathering last night with some local geeks, which is where the inset photo originates.

Hello, world.

Posted by adamjh on Jul 12th, 2007

Adam/Jeff at the beginningWelcome to fluxcapacity.  My name is Adam Herscher, and less than 2 weeks ago I left my job at Microsoft to start something new with my friend and former research project partner, Jeff Powers.

For years, we've been quietly sifting through the massive amounts of essays, books, blogs, movies, speeches, magazines, and personal experiences about starting something, while at the same time continuing to gain experience and  refine our own ideas until the time was right to dive in and make a go of it.

That time is now, and we're excited to use this space over the coming months to share our thoughts and adventures in building a software company together from the ground up.

So, where are we today?  We've moved a combined 3,000+ miles to crash at my parents' pad in Los Angeles, California, where we've appropriated some killer office space and set up shop.  We've been the lucky recipients of an unused long wood dinner table that makes for a fantastic work bench, an old warped but large whiteboard originally destined for whiteboard heaven, and are intently scoping craigslist for deals on used office chairs.

We've been here 5 days, and have spent 5 days coding, and are up to a codebase of roughly 9,438 lines (including code, comment, and blank lines across .cs, .cpp, .c, and .h files), minus whatever Jeff has yet to check in today.  For fun, we've decided to chart the size of our codebase over time on the right-hand side of our blog (which we realize is hardly a measure of anything other than new lines of code written minus lines of code refactored away, and thus we'll likely enhance at some point to perhaps take into account delta rather than quantity).

Questions we've discussed recently include:

  • When to seek out investment and from whom/how much
  • How many people to hire, how quickly, and whom
  • Which technology stack(s) to build on (LAMP vs WISC most notably)
  • What/when/how much to release (in terms of information/blogging, product, code)
  • Which interfaces to develop and prioritize (web? pc/mac/linux clients? mobile web? mobile j2me/.net? sms? iphone? facebook? gadgets/widgets? apis?)

We'll likely blog about our thoughts on these topics and quite a few others over the next few weeks, and as time progresses begin to share details of what we're actually trying to build.