Navigation

Search

Categories

On this page

How to : Sign XML messages with a SHA-1 signature, for Adobe Content Server
Avoid the slow Add Reference dialog box in Visual Studio 2008
The technology is there to build better software. are you doing it ?
Workaround – Error while installing VS 2008 SP1 and .Net 3.5 SP1
Measuring code readability ?
Martin Fowler Talk
COM Exception while loading a Web Application Project
I'm now an MCPD : Enterprise Application Developer
Do certifications matter ?
HOWTO Get the size of a file as a formatted string
How to contribute a patch to Open Source projects
Generate a DTD from an XML File
Windows Live Writer code syntax highligting plugin.
VS 2003 Service Pack 1 Released
How to create a MMC SnapIn using .Net
New Font for the Visual Studio 2005 Editor
UK Developer Day
.Net debugging tips

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 149
This Year: 2
This Month: 0
This Week: 0
Comments: 43

Sign In
Pick a theme:

# Sunday, February 14, 2010
Sunday, February 14, 2010 11:38:53 AM (GMT Standard Time, UTC+00:00) ( .Net General )

The past week I’ve been doing a spike to talk to Adobe Content Server 4 (ACS4). Querying the content in ACS4 is done in a REST style. The client sends a XML message via HTTP POST to the admin endpoint. The endpoint details are in the documentation but are vague.  This is usually at  http://youracs4server/admin/EndPoint.

These need a signed XML message, in the POST body. A typical message looks like this

<request>
    <nonce>ABCD123==</nonce>
    <hmac>XXXXXXXXX===</hmac>
    <distributor>uid:8888-43434-34343434</distributor>
   <resource>
     ......
   </resouce>
</request>

The hmac element contains the SHA1 signature  of the XML message. The signature is generated using a shared secret.  The signature is for the whole XML except the hmac element. Before signing the message, we have to construct the XML without the hmac, then sign it, and then add then hmac.

I did this by using a two stage Xml serialization process. This may not be the best way to do it, and there has to be a better solution.  I created a class named SignedXMLSerializer, and this inherits from XmlSerializer. SignedXMLSerializer serializes objects that are of the base type Signable. The Signable class has two properties, Nonce and Hmac. Any class that has to be sent as a signed XML message must inherit from Signable

public abstract class Signable
    {
        [XmlElement("nonce")]
        public string Nonce { get; set; }

        [XmlElement("hmac")]
        public string HMAC { get; set; }
    }

In the serialize method of the SignedXMLSerializer, we first generate the nonce. The nonce makes each message unique. Then we serialize the object to a string. The signature is generated using this string, and assigned it to the Hmac property.

We then serialize the signed object to the writer that was passed in.

public void Serialize(T o, XmlTextWriter writer) {
            o.Nonce = GenerateNonce();
            StringBuilder stringBuilder = GetXMLToSign(o);
            string hmac = GetSignature(stringBuilder);
            o.HMAC = hmac;
            Serialize(writer, o);
        }
To use the SignedXMLSerializer, pass in one of the HashAlgorithm types. I’ve used SHA1 in my case.
This makes it easier to use with different signing algorithms. 
Typical usage of the SignedXMLSerializer is as follows
HMACSHA1 hmacsha1 = new HMACSHA1 {Key = Encoding.ASCII.GetBytes("consumerSecret")};
            SignedXmlSerializer<Request> signedXmlSerializer = new SignedXmlSerializer<Request>(hmacsha1);

 StringBuilder sb = new StringBuilder();
            StringWriter writer = new StringWriter(sb);
            signedXmlSerializer.Serialize(req, new XmlTextWriter(writer));

The final serialized string can be sent via HTTP post to ACS4. 

Code for the SignedXMLSerializer class is here http://gist.github.com/303962

Comments [0] | | # 
# Saturday, November 28, 2009
Saturday, November 28, 2009 1:31:31 PM (GMT Standard Time, UTC+00:00) ( .Net General | development | TDD )

 

When you are in the zone, and want to add a reference to Rhino, NUnit or any other common reference, adding it via the Add Reference dialog can be painfully slow. Fortunately VS has a good automation interface, which lets you to write macros.

I wrote a simple macro to add a NUnit reference to the current project. Add this to your Macros project in Visual Studio, map a button or a shortcut key to it. This way you can add those common references pretty quick.

This is a cleaned up version of the sample here http://msdn.microsoft.com/en-us/library/vslangproj80.reference3%28VS.80%29.aspx

 

   1:      Sub AddNUnitReference()
   2:          AddNewReference(DTE, "C:\Tools\NUnit\nunit.framework.dll")
   3:      End Sub
   4:   
   5:      Sub AddNewReference(ByVal dte As DTE2, ByVal referencePath As String)
   6:          Dim aProject As Project
   7:          Dim aVSProject As VSProject
   8:   
   9:          aProject = dte.ActiveDocument.ProjectItem.ContainingProject
  10:   
  11:          aVSProject = CType(dte.ActiveDocument.ProjectItem.ContainingProject.Object, VSProject)
  12:          ' Add an Assembly reference and display its type and additional
  13:          ' information.
  14:          Dim newRef As Reference
  15:          newRef = aVSProject.References.Add(referencePath)
  16:   
  17:      End Sub
Comments [0] | | # 
# Thursday, December 11, 2008
Thursday, December 11, 2008 8:03:25 PM (GMT Standard Time, UTC+00:00) ( .Net General | Agile )

here is a random thought I had today.

From what I've seen, in the past 2 years, agile practices have spread among the .Net community.  The .Net framework  gives us the power to do TDD and follow other agile principles.  the community is now empowered with a rich API , so that we don't have to worry about how to build things.  We now have to worry about what we can build and how to build it better.

We have been freed from the shackles of VB and classic asp, with a good OO framework, that is getting better. You name the problem and there is a very good .Net based tool to help you solve it. You want mocking , you have Rhino Mocks, you want persistence you have NHibernate, you want testing APIs, you have Nunit, Mbunit and what not. 

The technology and tools to build better software is here, are you using it ? if not what's stopping you ?

Comments [0] | | # 
# Monday, August 18, 2008
Monday, August 18, 2008 10:58:32 PM (GMT Daylight Time, UTC+01:00) ( .Net General )

 

If you get an error with the message in the install log like;

dotnetfx35.exe failed with 0x80070643 - Fatal error during installation

It helps to run a manual cleanup of any .Net 3.5 framework installations before trying again. Use the automated cleanup tool here. Remove the .Net 3.5 version already installed. You may need to do it twice to do a complete cleanup. Then start the SP 1 setup again.

Comments [0] | | # 
# Wednesday, May 28, 2008
Wednesday, May 28, 2008 7:51:38 PM (GMT Daylight Time, UTC+01:00) ( .Net General | Software Design )

Thinking of ways to measure code readability. How easy is it to read and understand a  method, or class ?

Number of branches in a method ? more branches -> more complex  hence a more complex method  that is hard to read

Split the camel casing of a method/class into words and run some sort of word analysis to check if the words make sense ?

The analysis has to be automated, and run as part of CI ideally..

 

Comments [0] | | # 
# Thursday, March 20, 2008
Thursday, March 20, 2008 2:37:05 AM (GMT Standard Time, UTC+00:00) ( .Net General | Software Design )

Today, at work I was treated to a rare opportunity to attend a talk by Martin Fowler. I may or may not get the chance to hear someone who can profoundly inspire developers. with simple( sometimes obvious) nuggets of wisdom, that will make us build better software.

The talk didn't have a specific title, but centred around the theme of software design and how we go about it. His talk mostly focused on how keeping things simple can help build better software. This concept is obvious, but many of us loose sight of it.

look at what has already been done.

Similar problems have already been solved, someone out there knows how to solve it.  This is the basis of all the design patterns that have been collated by Eric Gamma et al and Martin Fowler himself.  Patterns are nothing new, they are not the future. They are practices that have been used in successful software in the past, and we can draw on the lessons learnt during the past 30 (or more)  years of software development.

spread knowledge backward

it's important that older, experienced developers pass on their knowledge to new or less experienced developers. He made an interesting point on how software architects at Thoughtworks pair up with less experienced developers. A good software architect is one who does not have to make any decisions. On a related subject Martin said "burn your architecture document". If the developers have to refer back to a document, it means that they haven't fully absorbed the architecture of the system being built, and there are gaps in their knowledge.

keep things simple, expect and prepare for change

This is what inspired me the most. Software is soft( malleable). It always changes, expect and be ready to change. Importantly be prepared to undo change. Work with what you know, and do not worry about changes that can happen. Postpone decisions till you absolutely need to make them. Organise work into incremental chunks of changes.

There is a lot more I took away from the talk. Might take a while to digest it all :). However these are concepts that are stressed in the books listed below, specially in The Pragmatic Programmer.

If you haven't read any of Martin Fowler's books, I strongly suggest you do so immediately, along with a few other books that will inspire ( and shock you) into being a better developer.

Patterns of Enterprise Application Architecture

Refactoring: Improving the Design of Existing Code

Domain-driven Design: Tackling Complexity in the Heart of Software

The Pragmatic Programmer

Kudos to Jason for organising the talk.

Comments [0] | | # 
# Saturday, March 01, 2008
Saturday, March 01, 2008 1:17:44 PM (GMT Standard Time, UTC+00:00) ( .Net General | .Net Web )

VS 2008 throws a COM Exception when loading a web application project. This happens when the project was made in VS 2005 and upgraded using the Upgrade Wizard. It loads web application projects made natively without a problem. There is a work around if this happens to you.

Via http://www.codeattest.com/blogs/martin/2008/01/comexception-loading-solution.html

"In order to load the Web Application Project you must make sure that the URL that the project is using, is valid and can be resolved. This can happen pretty often since when you download a project from source control for the first time, it is highly unlikely that you will have the web site already set up."

 

If this happens to you, the project will not load and will be grayed out in the solution explorer. Right click and edit the project, (or edit the .csproj file in notepad) look for the WebProjectProperties element. Check if the IISUrl child element points to a valid location. The server should exists, and the virtual directory should point to the same location as the web application project.

Comments [0] | | # 
# Tuesday, November 13, 2007
Tuesday, November 13, 2007 11:52:16 AM (GMT Standard Time, UTC+00:00) ( .Net General )

In the midst of fiddling with the Xbox, I took the second part of the MCSD to MCPD uprade exams. I got a  voucher to do the first part (70-553) at the Visual Studio 2005 launch event. I got around to doing the second part (70-554) yesterday. I passed with a comfortable 820. This is the last of the certifications till the .net 3.5 series comes out.

Comments [0] | | # 
# Sunday, July 15, 2007
Sunday, July 15, 2007 1:12:58 PM (GMT Daylight Time, UTC+01:00) ( .Net General )

http://www.codinghorror.com/blog/archives/000771.html

"The certification alphabet is no substitute for a solid portfolio; you should be spending your time building stuff, not studying for multiple choice tests. But that doesn't mean they're worthless, either. I don't think certifications get in the way, as long as you can demonstrate an impressive body of work along with them."

I couldn't agree more. I find that there is a misconception MS certifications are software development qualifications. Many budding developers think of this as a must have and expect to get programming skills through the certification program. They fail to realize that the MCP/MCSD/MCPD certifications are product certifications rather than programming certifications.

Comments [0] | | # 
# Friday, March 30, 2007
Friday, March 30, 2007 2:54:54 PM (GMT Daylight Time, UTC+01:00) ( .Net General )

Quick and dirty function to return the size of a file in a properly formatted string in KB, MB or GB. There has to be an easier way than this .....

 

    private const double KByte = 1024;
    private const double MByte = KByte * 1024;
    private const double GByte = MByte * 1024;

public static string GetFileSizeString(int bytes) {
        if ((bytes / GByte) < 1) {
            if ((bytes / MByte) < 1) {
                if ((bytes / KByte) < 1) {
                    return String.Format("{0} B", bytes);
                }
                else {
                    return String.Format("{0} KB", Math.Round((bytes / KByte), 2));
                }
            }
            else {
                return String.Format("{0} MB", Math.Round((bytes / MByte), 2));
            }
        }
        else {
            return String.Format("{0} GB", Math.Round((bytes / GByte), 2));
        }
        
    }
Comments [0] | | # 
# Sunday, January 28, 2007
Sunday, January 28, 2007 8:21:32 PM (GMT Standard Time, UTC+00:00) ( .Net General | OSS )

A nice step by step tutorial, on how to submit a patch/bug fix to a OSS .net project on Sourceforge.

How to contribute a patch

Comments [0] | | # 
# Monday, November 27, 2006
Monday, November 27, 2006 10:53:51 AM (GMT Standard Time, UTC+00:00) ( .Net General )

 

Handy online tool. http://www.hitsw.com/xml_utilites/

Comments [0] | | # 
# Sunday, November 26, 2006
Sunday, November 26, 2006 5:52:27 PM (GMT Standard Time, UTC+00:00) ( .Net General )

Make your code posts pretty.

http://puzzleware.net/blogs/archive/2006/10/29/CodeHTMLer-plugin-for-Windows-Live-Writer.aspx

  1 /// <summary>
  2 /// Summary description for Main.
  3 /// </summary>
  4 static void Main(string[] args)
  5 {
  6   // string variable
  7   string myString = "myString";
  8 
  9   /* integer 
 10      variable */
 11   int myInt = 2;
 12 }
Comments [1] | | # 
# Monday, August 21, 2006
Monday, August 21, 2006 10:13:06 AM (GMT Daylight Time, UTC+01:00) ( .Net General )
Monday, August 21, 2006 9:46:32 AM (GMT Daylight Time, UTC+01:00) ( .Net General | .Net Net | .Net UI )

Found this nice article.

Creating MMC Snapin using C# (Part I)

Requires a the MMC .Net library over at sourceforge.

http://sourceforge.net/projects/mmclibrary/

Comments [0] | | # 
# Tuesday, May 09, 2006
Tuesday, May 09, 2006 5:59:54 PM (GMT Daylight Time, UTC+01:00) ( .Net General )

Download here

Makes code more readable, works only if ClearType is enabled. Looks good on my laptop

via http://blogs.msdn.com/vseditor/archive/2006/05/08/593399.aspx

Update: Works with VS 2003 as well, just go to Tools ->Environment and set Consolas font for the text editor

Comments [0] | | # 
# Wednesday, May 03, 2006
Wednesday, May 03, 2006 10:30:17 AM (GMT Daylight Time, UTC+01:00) ( .Net General )

http://www.developerday.co.uk

Registrations are now open for DDD, on the 3rd of June.

 

Comments [0] | | # 
# Friday, April 28, 2006
Friday, April 28, 2006 11:25:38 AM (GMT Daylight Time, UTC+01:00) ( .Net General | Odds & Sods )

Added these blogs to my feed list.

http://blogs.msdn.com/tess

http://dotnetdebug.blogspot.com/

Tess's blog is full of  debugging and trouble-shooting tips.

http://blogs.msdn.com/tess/archive/2006/02/23/537681.aspx

Comments [0] | | #