Classes or XML Documents

One of the Four Basic Tenets of Service Orientation states that “services share schema and contract, not class”. This means the interface for a service should be based on an XML schema.  This runs counter to the interface for a managed class, where the type

Lowering the Barrier to Entry

If you've been wondering how you can afford a copy of Visual Studio .NET 2003 for playing with at home, you're request has been granted.  Simply watch and review five of the VB at the Movies installments found here and you'll get a certificate for a free Standard Edition.  Not a bad deal at all.

Get Ready for some Testing Fun

Burton has finally been officially announced.  The Visual Studio 2005 Team System is basically everything that VSS wasn't. 

  • Integrated Unit Testing
  • Code Coverage Tools
  • Enforced Check-In Policies (e.g. you must pass a unit test before the code can be checked in)

If you are a developer (as opposed to a straight coder), these changes are quite exciting.  I know I was impressed when I first saw them. Look for more information at the AskBurton blog.

 

Web Services News from TechEd

It has finally happened.  After what seems to be 10 years in the making (but what was probably only a year or so), Web Services Enhancements 2.0 has been released.  It can be downloaded here.

I've been using WSE in a limited role for a while now, mostly because it greatly simplified the attachment of certificates to a web service request.  Beyond this, one of the other nice additions to the standard is it's implementation of WS-Proxy/WS-SecurityProxy.  By using these standards, it becomes easy (as opposed to just possible with WSE 1.0) to send a secure, encrypted message and ensure that the message meets a certain level of security (the policy).

Look for some examples of how to use WSE 2.0 code in this venue over the next few days.

Objects and Web Services

I've  been asked this question enough both on-line and in person that I thought a blog might be a better way to clear up a common misconception. Consider the following situation.  Your application has implemented a class as follows:

public class Dog
{
   public string Breed;
   public string Fetch()
   {
      return "stick";
   }
}

As well, the application has a web service method defined like the following:

[WebMethod]
public Dog GetDog()
{
   return new Dog();
}

So let's move to the client side. In a typical .NET application, you would add a web reference pointing to the web service that includes the GetDog method just described.  Under the covers, Visual Studio .NET invokes wsdl.exe to generate the proxy class. Because of the magic of this tool, not only is a proxy for the web service created, but so too is a class that represents the Dog class that is returned from GetDog.  This means that, on the client side, there is no need to deploy the assembly that implements the Dog class on the server-side.  Or does it.

If you open up the .cs file generated by adding the Web Reference (you might have to “show all files” in the Solution Explorer then navigate to below the Reference Map in the Web Reference - the file is called Reference.cs), you will find a class called Dog defined. Does the automatic addition of the Dog class make it easy for developers to work with web services?  Yes. Does it cause some level of confusion?  Definitely.  Which is the reason for this post.

Take a close look at the Dog class in Reference.cs.  What you will see is a class that contains all of the public properties that were exposed by the server-side Dog class.  What you will *not* see is any of the business logic that might have been implemented in the server-side Dog class.  Nor will you see any methods, public or otherwise.  In other words, these two classes are absolutely not the same class, regardless of the similarity in naming. 

What kind of problem does this cause? Say you actually deploy the server-side assembly onto the client and try to pass an object of that type (the server-side Dog class, that is) into the web service method call.  The result is that an apparently inexplicable InvalidCastException error gets thrown.  The reason for the exception is because the server-side Dog class is not the same Dog class defined in the proxy class.  That should make sense now, but it throws a lot of new web service developers for a loop.

There is a solution to the problem.  Once the proxy class has been created, edit the Reference.cs file directly.  Remove the Dog class from that file and change the return type for the GetDog method to match the server-side Dog class.  Now the InvalidCastException will go away.  Keep in mind that, should you decide to refresh the Web Reference, then you will have to make these changes again.  So when I do this kind of manipulation, I would typically use wsdl.exe manually to create the proxy class file and they add it into the project.  This eliminates the potential for wiping out the changes accidentally.

 

ObjectSharpees at TechEd

I am lucky enough to have two of my ObjectSharp colleagues running two separate Birds of a Feather sessions.  Barry Gervin is hosting “Integrating Unit Testing tools and practices into the Software Development LifeCycle” on Sunday at 8:00 pm.  Barry has been waist deep in unit testing design and implemention for quite a while now.  Trust me that his knowledge is based on nicks, cuts and scars rather than book lernin'.

Also, Marcie Robillard (that's Datagrid Girl to the rest of the world) is hosting a BOF session on Wednesday.  The topic is basically whatever her fertile mind dreams up.  Be afraid.  Be very afraid.

If you're attending TechEd, make sure you stop in and see what they have to say.

You Know Blogging Has Arrived When...

A quote from Bill Gates' keynote at the Microsoft-hosted CEO Summit.

“Another new phenomenon that connects into this [collaboration] is one that started outside of the business space, more in the corporate or technical enthusiast space, a thing called blogging. And a standard around that that notifies you that something has changed called RSS.”

I guess we can all sleep easier now that our life's work has been validated. ;)

Actually, the most interesting thing about Bill's comments is that he pitches it as being, in some ways, superior to email as a communications medium.  Less intrusive and less prone to CC-spamming (that's when some CC's everyone and their mother on an email to ensure that no one feels left out). And when you're talking about blogging to Warren Buffet, Barry Diller, et al. odds are pretty good that the level of corporate interest in RSS will increase over the next six months. 

 

 

A New ObjectSharpee

As of tomorrow, ObjectSharp welcomes another member to our team.  For those of you who already know her, the color of this post is a giveaway clue.  If you're not familiar with her work, you can read more about it here.

Talking Without an Audience

I had the unexpected opportunity earlier today to do my first MSDN DevChat webcast.  Or a webcast of any kind. One of my colleagues, Dave Lloyd was giving a webcast on the new features in ASP.NET Whidbey.  The webcasts originated from the Microsoft Canada office and I went along to be his question monkey and to provide an audience. Once I got to Microsoft, Adam Gallant offered me the chance to do a webcast on C# scheduled for two hours later. Never being one to turn down a chance to speak, regardless of the circumstances, I accepted.

For those of you who have never done a webcast, the process is straightforward.  We were in a small conference room, four of us in total. The presenter (Dave) is hooked up to the LiveMeeting manager and a headset.  Dave basically controls the slides and demos and speaks into the headset.  The rest of use handle any questions or issues as they arise.

The weird part of the process is something that presenters will understand.  I personally thrive on the interaction that I get from speaking in front of an audience.  More importantly, I tend to adjust what I say and how I say it based on the feedback that I get.  If I see a glazed look, I dial back on the details.  If I hear snoring, I rachet up the 'coolness' factor. You get the picture.

The challenge of a webcast is that none of this feedback is available.  You're in a room talking on the telephone without the benefit of seeing or hearing the audience.  It is a surprisingly isolated experience.  To make it even worse, the other people in the room have their own conversations going on (quietly, of course) as they answer questions and deal with problems. I just ended up closing my eyes and kept going forward.

So the next time that you're listening to a webcast, feel free to chime in with any questions or feedback your have.  It will probably be welcomed by the speaker, if only to let them know that there really are people on the other side of the network connection.

RSS Feeds and DataSets

So as I write this at 1:10 in the morning, I have just finished beating my head against a fairly hard wall.  The task was to load an RSS Feed into a DataSet.  Then once in the DataSet, the feed could be bound to a Datagrid, a DataRepeater, etc.  The plan was simple.  The strategy sound. Or so I thought.

"No plan survives contact with the enemy." -Field Marshal Helmuth von Moltke.

While I suspect that many of you are aware of the quote, it´s place in the process of strategic is frequently forgotten.  The quote is intended to remind strategists to set broad objectives and seize unexpected opportunities when they arise. Of course, in this instance, I´m using the more pessimistic “stuff happens“ meaning that is more commonly ascribed to the quote.

So I naively start the process by creating a DataSet object and using the ReadXml method to build it.  Due to the foresight of the .NET Framework designers, I can simply pass the URL to the RSS Feed as a parameter.  Sweet.

But then I run into a snag. Or, to put it another way, Moltke proved his prescience. Within ReadXml, a DuplicateNameException is thrown. The specific message was  “A column named 'comments' already belongs to this DataTable.“ After an examination of the RSS feed, I discovered that the Slash RSS module uses a Comments tag. In the RSS feed, it is properly namespaced, but the namespace is not recognized by ReadXml.  So the Comments tag in RSS clashes with the Comments tag in Slash RSS.

The solution to this problem is not as clean as I would have liked.  In my ideal world, there would be a way to limit the namespaces that are loaded into the DataSet.  Perhaps using the XmlNamespaceManager, for instance.  But for all the Googling that I did, there doesn't appear to be any solution down this alley. So instead I turned to a kludgey (from my perspective) method that involves transforming the RSS feed using XSL.

My next problem immediately followed this solution.  When I processed the transformed RSS feed, another exception was thrown.  This time it was a ArgumentException that read "The same table (p) cannot be the child table in two nested relations.". Back to the RSS feed we went.  What we saw was that if the post was XHTML compliant, then a separate <Body> block was contained within the post.  In this <Body> block was the post complete with the various markup tags (like <p>) intact.  This differs from the normal format of the post, where the angle brackets surrounding the tag are converted the &lt; and &gt;. The result was that ReadXml was choking on the fact that <P> existed in to separate items.

Back to the XSL, where I excluded the <Body> block from the RSS feed.  Now my XSL file looks like the following:

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"   
     xmlns
:slash="http://purl.org/rss/1.0/modules/slash/" 
     xmlns
:xhtml="http://www.w3.org/1999/xhtml" >

    <xsl:template match="*|@*|comment()|text()">
       
<xsl:copy>
           
<xsl:apply-templates select="*|@*|comment()|text()"/>
       
</xsl:copy>
    </
xsl:template>

    <xsl:template match="slash:comments">
        <SlashComments>
            <
xsl:apply-templates select="*|@*|comment()|text()"/>
        </
SlashComments>
    </
xsl:template>

    <xsl:template match="xhtml:body"></xsl:template>

</xsl:stylesheet>

Mission accomplished.  I now have a DataSet that contains the necessary information from an RSS Feed.  Next up is to actually bind it to the desired control.  Haven't gotten around to it yet, but I'm hoping that it is much easier.  It certainly shouldn't be much more challenging.