Between the Lines Article

As much as I don't like to toot my own horn, I'm proud of the fact that I'm now officially published on an MSDN site.  If that isn't worth a “Woo Hoo!!”, I don't know what is.

XAML IntelliSence Patch for PDC "Whidbey" & "Longhorn"

Overview The IntelliSense in the PDC bits while editing XAML had problems inside Style elements as well as when completing tags and reformatting. This patch addresses those issues to improve the developer experience.

System Requirements
PDC '03 release of Longhorn
PDC '03 release of Visual Studio .NET "Whidbey"

Download: XAML IntelliSence Patch for PDC Visual Studio .NET Whidbey

Whidbey

Next Tuesday (Dec 9th) Object Sharp is hosting a free half day seminar on VS.NET 2.0 (Code Named Whidbey).  We'll show a lot of the new features in the IDE like snipits, expansions, snap lines and smart tags. We'll show you new features in C# and VB.NET, also ADO.NET and ASP.NET.

I think you will really enjoy this informal look at the next wave from a developers perspective.

Come on out. It's free and you just might learn something. You can register here.

 

VB who knew?

I haven't written anything in my Blog for quit some time. Mostly because I have been preparing for presentations. We helped Microsoft with their Bigger Better Basic cross Canada tour last month. I spoke in Toronto, Ottawa and Vancouver. It was great. We met lots of wonderful people who were all very excited about Web Services and Client Applications. I'm sure you can tell by the name that the show was for VB developers. My colleagues will tell you it's pretty humorous to say the least that I would wind up speaking to VB developers about how great VB.NET is to develop in.

At one time I would have nothing to do with VB. It was not Object Oriented, that was enough right there. ADO was not great, ASP was not great. It was just too hard to do anything. Well I'm hear to tell you, “VB has come a long way baby“. I was speaking with someone at the show on this very subject. They said “If you told me 1 year ago VB would one day have Generics I wouldn't have believed it”

I still prefer the syntax of C#. In a paste life I was a C developer so I am used the the sparse syntax and I like curly brackets. However, although I still find VB a bit verbose for my taste. I have been developing an application with it and it's a good language, VB.NET has a lot going for it.

WSDL and XSL

If this solution is familiar to experienced XSL users, forgive me.  I'm a casual XSL user, so the problem was difficult to identify and I didn't find much in the way of Google entries covering the answer.  So that (in my small, secluded little world) makes it blog-worthy.

The situation I found myself in was needing to convert the WSDL output from an ASP.NET page to a specific XML format.  The reason for the format is irrelevant.  Suffice it to say, that I needed to create a list of the valid SOAP operations for a particular web service.  I tool the WSDL that was generated by ASP.NET and started the trial and error process of identifying the correct XSL stylesheet to use.  This is where I ran into problems.

I do understand the basics of XPath enough to try simple queries.  My starting point was to list out the portTypes for the WSDL.  To do this, my initial XPath query was //definitions/portType.  This didn't actually return any nodes.  I thought this strange, so I dropped down to the more straightforward //definitions.  This too returned nothing.  Running out of drop-back room, I went with the wildcard //*.  Fortunately for what remains of my hair, this worked. So the question of why the other queries didn't work remained.

After more painful attempts (and a weekend to allow my brain some reset), I finally came across the solution.  XPath queries don't work with the empty namespace.  They require that the namespace be explicit within the query.  But the WSDL generated by ASP.NET does not assign a namespace to the WSDL elements, choosing to use the empty namespace.  So the XSL file needed to be modified to define a namespace for the URI associated with the WSDL elements.  When done, the xsl:stylesheet element looked like the following:

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" >
 

The key here is the xmlns:wsdl attribute.  This defines a namespace called wsdl and associates it with the listed URI.  This URI needs to match exactly the URI associated with the empty namespace in the WSDL file.  And I do mean exactly.  Character for character.  Byte for byte. 

Once this has been added to the stylesheet tag, the XPath queries can be modified to be //wsdl:definitions/wsdl:portType and the results will be as expected.

The Structure of a SOAP Message

In order to gain a complete understanding of services-oriented architecture (SOA), one of the basic pieces of knowledge is the structure of a SOAP messages.  At a high level, SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment.  But that description gives short shrift to the true utility of SOAP, that being the transmission of a request for service between two heterogeneous and networked applications.  In this article, we look at the structure of a SOAP message in great detail, as well as put the SOAP message into the context of the HTTP request.  This second part has to potential to be a fleeting reference, as there is nothing in the SOAP specification that requires that HTTP be the conduit.  However the ubiquity of HTTP has made it the de facto standard for transmission and it will probably be a few years before it is displaced.

 

For the purposes of this document, SOAP is a Remote Procedure Calling protocol that works over HTTP.

The body of the request is in XML. A procedure executes on the server and the value it returns is also formatted in XML.

Procedure parameters and returned values can be scalars, numbers, strings, dates, etc.; and can also be complex record and list structures.

Request example 

Here's an example of a SOAP request:

POST /examples HTTP/1.1
User-Agent: Radio UserLand/7.0 (WinNT)
Host: localhost:81
Content-Type: text/xml; charset=utf-8
Content-length: 474
SOAPAction: "/examples"



   
      
         41
         

      

   


Header requirements 

The format of the URI in the first line of the header is not specified. For example, it could be empty, a single slash, if the server is only handling SOAP calls. However, if the server is handling a mix of incoming HTTP requests, we allow the URI to help route the request to the code that handles SOAP requests. (In the example, the URI is /examples, telling the server to route the request to the "examples" responder.)

A User-Agent and Host must be specified.

The Content-Type is text/xml. The charset may be specified, if not, the default is US-ASCII. Other acceptable charsets are UTF-8 and UTF-16. UTF-8 is recommended for maximum interop. See the note on UTF character encodings, below.

The Content-Length may be specified, if it is, it must be correct.

As with the URI in the first line, SOAPAction is used to route the request to a handler on the server that will respond. It's entirely up to the application to determine how this header element is used. In many implementations the URI and the SOAPAction header will have the same value.

Payload format 

The payload is in XML, a single element.

All the attributes of the are required as shown in the example above.

The must contain a single element, which contains a single element which is the procedure call. The name of the procedure is the name of this element. Note that the procedure name must be a valid XML element name.

The elements contained within the procedure call are the parameters to the procedure. The names of the parameters is significant, the order of the parameters are not. Parameter type is indicated by the xsi:type attribute.

For example, the procedure name could be the name of a file containing a script that executes on an incoming request. It could be the name of a cell in a database table. Or it could be a path to a file contained within a hierarchy of folders and files.

A procedure call may take no parameters, if so, the procedure element must not contain sub-elements.

Scalar values 

The following scalar value types are supported by this subset of SOAP 1.1.

Type value Type Example
xsd:int 32-bit signed integer -12
xsd:boolean a boolean value, 1 or 0 1
xsd:string string of characters hello world
xsd:float or xsd:double signed floating point number -12.214
xsd:timeInstant date/time 2001-03-27T00:00:01-08:00
SOAP-ENC:base64 base64-encoded binary eW91IGNhbid0IHJlYWQgdGhpcyE=


Structs 

A value can also be a struct, which is specified by an XML element that contains sub-elements. structs can be nested, and may contain any other type, including an array, described below.

Here's an example of a two-element struct:


   18
   139
   

The names of struct elements are significant, the order of the elements is not.

Arrays 

A value can also be an array, which is specified by an XML element with a SOAP-ENC:arrayType attribute whose value begins with ur-type[, followed by the number of array elements, followed by ].

Here's an example of a four-element array:


   12
   Egypt
   0
   -31
   

The order of array elements is significant, the names of the elements are not.

You can mix types as the example above illustrates.

If the array elements are of a single type, the value of the array element's SOAP-ENC:arrayType specifies the type of the array's sub-elements, for example, SOAP-ENC:arrayType="xsd:int[4]" means an array of four xsd:int elements.

For mixed-type arrays, the SOAP-ENC:arrayType attribute always specifies xsd:ur-type.

For single-type arrays, the xsi:type attribute is optional for array item sub-elements, but its inclusion is recommended.

Null values 

A value can also be a null, which is specified by an XML element with an attribute, xsi:null, whose value is 1 as follows: .

Response example 

HTTP/1.1 200 OK
Connection: close
Content-Length: 499
Content-Type: text/xml; charset=utf-8
Date: Wed, 28 Mar 2001 05:05:04 GMT
Server: UserLand Frontier/7.0-WinNT



   
      
         South Dakota
         

      

   


Response format 

Unless there's an error, return 200 OK.

The Content-Type is text/xml.

Content-Length may be specified, if it is, it must be correct.

The body of the response is in XML, a single element.

The must contain a single element, which contains a single element which is the returned value of the procedure.

The single element contained in the has an arbitrary name which must match the name of the procedure that was called, with the word "Response" tacked on to the end of its name. Let's call this element the wrapper for the response. Even this is not the actual value of the response, which is contained in the single optional sub-element of the wrapper and must be a valid parameter.

The namespace of the wrapper element should match the namespace in the request.

If the wrapper has no sub-elements then the procedure did not return a value

Fault example 

HTTP/1.1 500 Server Error
Connection: close
Content-Length: 511
Content-Type: text/xml; charset=utf-8
Date: Wed, 28 Mar 2001 05:06:32 GMT
Server: UserLand Frontier/7.0-WinNT



   
      
         SOAP-ENV:Client
         Can't call getStateName because there are too many parameters.
         

      

   


Fault format 

If there's an error return 500 Server Error.

The may contain a which must contain two elements, and .

is intended for use by software to provide an algorithmic mechanism for identifying the fault. is intended to provide a human-readable explanation of the fault.

A may not contain both a and a wrapper (returned value).

When to fault 

If you can't process a request, for any reason, you must generate a fault.

Examples of fault conditions include:

1. An element or attribute in a request that is in an XML namespace which has not been declared.

2. A header in the request with a mustUnderstand="1" attribute that you don't understand.

3. A parameter is of a type that you don't support.

re: Gotta Love Misinformed Authors Spreading FUD

I have no problem with the opinion that Steve Gillmor shares both in his original eWeek article or in his subsequent comments in Drew's blog on the topic.  Specifically, I appreciate his willingness to stand behind his views.  To quote Mr. Gillmor,

“As for Robert Scoble, he is certainly capable of standing behind his own views when he wants to. I certainly stand behind mine.”

I take issue, however, with exactly what he is standing behind.  Is it the view that XAML stands for the Transaction Authority Markup Language?  Is it the opinion that Longhorn “veers-away” from some unstated (and, to the best of my knowledge, non-existant) standard that separates the layout and logic portions of an application?  Could it be that he stands behind the idea that developers create applications using the XSD 'language'?  Or that programmers will have to 'unlearn' XSD once Longhorn arrives. If so, it might be better to find a more stable platform on which to make your stand.

The idea that I'm going to have to wait until 2006 before getting access to some of the functionality that will be available in Longhorn is frustrating to me as a developer.  Sometimes ignorance can be bliss.  But I balance my frustration with the ability to better plan my current application architectures.  Do I expect to include XSD/XML functionality in my current code?  Certainly, assuming that I want my applications to be able to exchange data with not only other Microsoft products but the rest of the computing world.  Do I expect that arrival of Longhorn to change my use of XSD/XML?  Only in the integration that my apps have with the file system on which they are running.  The rest of the world speaks XML and I don't think that Longhorn will change that significantly.  Nor is the release of Longhorn likely to make my life as a developer more difficult, as Mr. Gillmor suggests.  If I take advantage of the information that is being made available by Redmond now, I should be ready for it, whenever it gets here.

Defining the Longhorn Battleground

Along with Sam Gentile and Drew Marsh (and others, I'm sure), I had a chance to read the eWeek opinion piece Can Microsoft's 'Longhorn' Pull it Off?.  Is this article an accurate representation of the facts that surround Longhorn?  Not even close.  Does the article display a lack of understanding by the author of the basic technologies used in Longhorn?  Yes.  But even if you completely eliminate the chaff, there is still an interesting element that can be gleaned from the approach taken by Mr. Gillmor.  What you are seeing is the initial 'shot across the bow' - the angle that Microsoft bashers will take as they attempt to capture mind- and developer-share.

The problem is that, without knowledge that can only be gained by playing with XAML and WinFS or reading articles and documentation on the topic, there is no way for the casual developer to tell the different between eFact and real facts.  I guess that means it's time to fire up the old Remington and produce some content more directed to the general masses.

CTT .Net User's Group - Instrument Your Application using Enterprise Instrumentation Framework - Nov 26, 2003 - Toronto - -12

Regardless of whether you are creating the next killer application or reworking your external facing interface using web services, your application is expected to play nicely with others. When it comes to administrators, ‘playing nicely’ means providing the appropriate amount of tracing and logging information. And for this, your code must be instrumented.

Once you have identified this need, the question is how to do it as easily as possible. The answer to this might very well be the Enterprise Instrumentation Framework (EIF). In this presentation, we take a look at the capabilities offered by the EIF, a free framework provided by Microsoft. In particular, we examine the basic structure of the framework, the possible outputs (SQL Server, WMI, MSMQ, and text-based log files to name a few) and the runtime flexibility that is offered. If you need to include trace and logging information in your code, then you will most definitely benefit from this talk.

Identifying New Records

While the use of AutoNumber and Identity fields in tables is greatly applauded by database designers the world over, they can be annoying for developers to use. The problem being that, when we add records to the database, there are many cases where we need to know the key of the record that has just been added. Fortunately, there are a number of techniques that are available to assist us in our task. In this article we look at the methods for both SQL Server and Access, with an eye to the pros and cons of each approach. As always, our goal is to give you enough information to make up your own mind

SQL Server

SQL Server 2000 offers three, count 'em, three options for retrieving the Id of a recently added record. The 'best' method depends on what you're doing and what else might be going on in your database. In all cases, the Id is a field marked as the primary key of a table and that has the Identity property set to True.

@@IDENTITY This is an intrinsic variable in SQL Server that contains the Id of the record that was last created on this connection, regardless of the table.
IDENT_CURRENT('table') This function returns the ID of the record that was last created in the specified table.
SCOPE_IDENTITY This variable contains the Id of the last record that was created within the current scope, regardless of the table.

So what are the ramifications of using each of these options? With @@IDENTITY, you get the most recent identity on the current connection. That means that if, as part of the INSERT statement, triggers get executed that in turn INSERT records into other tables, @@IDENTITY contains the last Id that was generated. Regardless of the table into which the record was inserted. Now if you created all of the stored procedures, triggers and INSERT statements yourself, that is fine. You can control when the @@IDENTITY value is being checked. But what happens if, sometime in the future, another developer, who is unaware that @@IDENTITY is being used, adds a trigger that creates an Audit log record. All of a sudden, @@IDENTITY returns a different id.  And not the one for the just added record.  As a result, your application breaks even though 'nothing' has changed. And that is the kind of bug that we all just love to track down.

The IDENT_CURRENT function is best used when you can control who has access to the database and when. By specifying the table as part of the function, you can eliminate the issues associated with @@IDENTITY. At least as far as the addition of records in triggers goes,   However IDENT_CURRENT works at the table level, not the connection level.  It returns the most recently created id, regardless of who created it. Unfortunately, in a busy environment, developers can't be sure between the execution of the INSERT command and the retrieval of IDENT_CURRENT, a different record isn't inserted by another user.

The SCOPE_IDENTITY instrinsic variable addresses some of the issues raised with the other two methods. Its value is the last Id created within the current scope. Athough technically the scope is the current connection, practically, the scope is more typically the currently executing stored procedure. Now you don't have to worry about the possibility of future enhancements 'breaking' your code, nor do you have to deal with other activity impacting the Id that is returned. If you perform more that one INSERT in a stored procedure, you do need to use the SCOPE_IDENTITY between each statement in order to retreive all of the created Id's. But again, that is within your sphere of control.

Unfortunately, if you are using SQL Server 7.0 or earlier, then the @@IDENTITY method is the only choice available to you. Both IDENT_CURRENT and SCOPE_IDENTITY were introduced with SQL Server 2000.

Microsoft Access

With Access, you are limited to basically a single technique. On a positive note, the same technique works all the way back to Access 97

First of all, I assume that we are inserting a record into a table where the primary key has an AutoNumber type. The addition of the record must be accomplished by using the AddNew and Update methods of the ADO Recordset object. Then, once the record has been added, store the absolute position of the new record and perform a Requery. Finally, set the cursor back to the bookmarked record and read the Id. Seem like a lot of work? And inflexible to boot? Such is the joy of Access

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open "DSN=MyDSN;"

rs.CursorLocation = adUseClient
rs.Open "SELECT CustNo, CustomerName, Contact", cn, adOpenStatic, adLockOptimistic

rs.AddNew

' CustNo is the AutoNumber field
rs.Fields("CustomerName").Value = "ObjectSharp"
rs.Fields("Contact").Value = "Bruce Johnson"
rs.Update

' The record has been inserted, but rs.Fields("CustNo").Value is zero
bookmark = rs.absolutePosition
rs.Requery
rs.absolutePosition = bookmark

' Voila
MsgBox rs.Fields("CustNo").Value