Monday, 24 December 2007

How to change the version of HTTP that your .NET web-service client proxy class uses ...

.NET uses HTTP version 1.1 by default for HTTP traffic. There are a number of differences between HTTP 1.1 and HTTP 1.0, so if you are talking to a HTTP 1.0 web-service (which you will be if you are talking with a Java web-service), then your generated .NET client proxy class will not be able to successfully communicate. This is frustrating, given the fact that you can read and process the WSDL, and build a client against it, but then not use the web-service.

The easy work-around for this problem is to use a .NET 2.0+ Partial Class - as follows:


using System;
using System.Net;

public partial class YourProxyClassName
        protected override System.Net.WebRequest GetWebRequest(Uri uri)
            // set proxy config while we are in here
            WebRequest.DefaultWebProxy = null;

            System.Net.HttpWebRequest req;
            req = ( System.Net.HttpWebRequest)base.GetWebRequest(uri);

            req.ProtocolVersion = System.Net.HttpVersion.Version10;
            return req;


This code effectively overrides the version of HTTP that is used, replacing the default of version 1.1, with version 1.0.

Friday, 14 December 2007

XSLT replace - the code

Extending on my post earlier today - thought I may as well include the code:

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl=" " version="1.0">

<!-- reusable replace-string function -->
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:when test="contains($text, $from)">
<xsl:variable name="before" select="substring-before($text, $from)"/>
<xsl:variable name="after" select=" substring-after($text, $from)"/>
<xsl:variable name="prefix" select="concat($before, $to)"/>
< xsl:value-of select="$before"/>
< xsl:value-of select="$to"/>
< xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$after"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
<xsl:value-of select="$text"/>
</ xsl:otherwise>

<!-- test the function -->
<xsl:template match="/">
<xsl:call-template name="replace-string">
<xsl:with-param name="text"
select="'Mary had a little lamb, little lamb, little lamb.'"/>
<xsl:with-param name="from" select="'little lamb'"/>
<xsl:with-param name="to" select="'little steak'"/>
Will make life a bit easier if I ever come to use this code again ;-)

XSLT output-tokens function ...

This can be used to split a string into tokens and add <br />s where appropriate:

<!-- reusable tokening function -->
<xsl:template name="output-tokens">
<xsl:param name="list" />
<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />
<xsl:variable name="first" select="substring-before($newlist, ' ')" />
<xsl:variable name="remaining" select="substring-after($newlist, ' ')" />
<br />
<xsl:value-of select="$first" />
<br />
<xsl:if test="$remaining">
<xsl:call-template name="output-tokens">
<xsl:with-param name="list" select="$remaining" />

very handy ...

Test Email Blog

Testing 123!

XSLT replace(,,) in VS200* ...

I would really like to be able to use the XSLT replace(,,) function in some work that I'm doing right now - but it seems as though I'm not able to, even in VS2008, because the .NET framework class libraries only support XSLT and XPath 1.0.

Have looked into Saxon for .NET, but there seems to be almost no documentation avialable as to how to use this component. The VS2008 XSLT debugger is actually superb, so I'm a bit baffled by this lack of support for XSLT and XPath 2.0 :-/

Anyway, I was sent this link ...

Which provides a code-listing that implements a custom search-and-replace function in XSLT. Works like a charm ;-)

Wednesday, 7 February 2007

DAL Ponderings ...

Here's something I have just posted to the NZDNUG (NZ .NET User Group) sql-server mailing list that I thought might make for a useful post:

"Hi all,

I have just completed a largish project designing and building a back-end system that is implemented across a series of processes, some of which are multithreaded. I have effectively designed and built this system from database design through to external interface implementation. A relatively complex system by requirement, but it has all come together fairly nicely (pats self on back ;-)).

What I have come to realise however in looking back at this experience, and in stepping back and looking at the 'complete' system, is that the part where things get a little twisted is in my sproc implementation. Although it all works nicely, I find that development of TSQL and SQL scripts in general, when compared to .NET (and OO) development tends to get a little 'hairy'. I find that TSQL and SQL don't really lend themselves to structured software design techniques, so I just tend to develop scripts (using as much foresight and caution as is practical of course) as the need develops.

I've studied databases to stage III at university, and have worked closely with databases throughout my IT career, but have found that there is not much documentation out there (or perhaps I've just not come across much) that goes into in-depth theoretical detail as to how sprocs can be organised in a structured manner.

I'd like to open a discussion about this to investigate what peoples thoughts are in this regard.



And another one:

"…further to my previous email…

For example – you have then need to access/update/insert lots of small bits and pieces of seemingly unrelated data – some scalar, some that would return/update/insert only a few 'small' records. Lump them all together in a single API type sproc ( i.e. pass thru a parameter, and receive back the appropriate data/confirmation), or make a separate sproc for each?

Another scenario - you have large chunks of data that are being pushed and pulled through a system. The data has potentially been modified as it is shifted around. The database code needs to ( i.e. it is appropriate for the db code to) analyse it to be able to determine if a change has occurred, then marshal the data accordingly. The data may be passed in this way though several different marshalling 'gates' before it finds it's way to it's home in the db table(s). Is it best to generate a tree-like series of sprocs that the data percolates though before it reaches the tables, or try to lump the whole thing into a single script?

What I'd like to be able to develop I think is a more mature way of managing the problem of data manipulation through the sproc 'layer'. Ideally I'd like to be able to apply some methodology - in the same way I can organise my .NET code into manageable portions by employing OO methodologies.

After some development experience it does seem to become clearer to distinguish which section of a data manipulation procedure should be performed in db-side code and which shouldn't. Some discussion on this topic would also be warranted though I think, especially with the onslaught of technologies such as DLINQ which are set to dissolve these db-side/custom-app-side data manipulation boundaries even further.


Edit - 20101016:

When I originally made this post on the NZ .NET user group mailing list, several senior developers came back to me and said bluntly "don't put that business logic in your database" and/or "the RDBMS is designed for data, not code"...all I can say is, they were so, so right...

Migrating (and Open-Sourcing) an Historical Codebase: SVN-to-Git

I have a SVN repo on my local machine that I have been shoving stuff into since before I knew how to use revision control systems properly (...