About WebDav: using IT Hit .Net library ..

Facing an integration task using WebDAV brought me to take a look closer at WebDAV and corresponding tools for .Net platform. This is part of a short series:

-----

Even if inventing your own wheel could be fun, it’s not always reasonable thing to do. I couldn’t find any freeware trustworthy-looking clients with brief googling so the first candidate is a commercial client - WebDAV client library from IT Hit, whose pricing starts from 350 USD.

What do I need ?

The simplest scenario you can get from WebDAV:

  • List folder contents, get name/urls, size, differentiate files & subfolders
  • upload a file from memory
  • download a file to memory

For testing purposes I use IIS 7.5 as my WebDAV server.

What Does it do?

Homepage promises compatibility to WebDAV RFC 2518.

More interesting features include:

  • requires .Net Framework 2.0 or .Net Compact Framework 2.0 SP1
  • high-level API
  • versioning support (DeltaV)
  • resumable uploads-downloads

What did I get ? / How did I do it ?

As expected, I achieved my supersimple goals.

Initializing the client:

string license = File.ReadAllText("WebDav-.net client_License.xml");
var session = new WebDavSession(license);
session.Credentials = CredentialCache.DefaultNetworkCredentials;
IFolder folder = session.OpenFolder(folderUri); //work in this folder.

Note that licence information has to be applied in-code in xml format.

Creating a IFolder is not mandatory for all tasks but as I happen to work in a single specific folder then I’m reusing the same object and declaring it next to the master-object session. Now, let’s see what’s in that folder..

foreach (IHierarchyItem item in folder.GetChildren(false))
{
if (item.ItemType != ItemType.Resource) { continue; }
Console.WriteLine("{0} ({1} bytes)",
item.DisplayName,
((IResource)item).ContentLength
);
}

Note that API is not the MOST readable: that “false” means non-recursive, files are called “resource” and even though most common properties are present in IHierarchyItem, file size is not. Code sample excerpts on home page were of no use. Also, I could not find it from object during runtime because the assembly code is obfuscated. Whatever, solution was found only after digging into IT Hit sample application. Let’s go download a text file contents..

var downloadResource = folder.GetResource("bb.txt");
using (Stream stream = downloadResource.GetReadStream())
using (var reader = new StreamReader(stream))
{
var contents = reader.ReadToEnd();
}

There was sample code present and the simple task gets simple solution. I’m getting used to looking for Resources. Possibility to get a file by local name (as opposed to always working with full URI) is a nice touch. Next task is to upload a file ..

var newFileName = "NewFile_" + DateTime.Now.ToString("dd-HHmmss") + ".txt";
var content = "Whatever content";

var uploadResource = folder.CreateResource(newFileName);
using (var datastream = new MemoryStream(Encoding.Default.GetBytes(content)))
using (Stream uploadstream = uploadResource.GetWriteStream(datastream.Length))
{
datastream.CopyTo(uploadstream);
}

Create resource in folder and get stream to write to that resource – seems reasonable. The downside is that if I do not know my data stream length in advance then I could be in trouble. There probably are some workarounds, but these API calls just happen to have that limitation. Just beware.

What do I think ?

The API is high level and using code exercpts in IT Hit home page you could get most of your tasks done relatively fast. I would trust it to do the job, espectially trickier stuff.  Still - I didn’t get the feeling that “this is The Tool to use for WebDAV”. Far from it.

The good:

  • decent API
    • you really don’t need to know much about webDAV.
    • Some helpful abstractions and hiding of webdav properties are a helpful for quickstarters
  • Commercial product but
    • Has evaluation option (1 month)
    • even entry level has royalty-free redistribution with your software.
    • source code option is available (for extra fee ofc)
  • Seems reliable
    • I ran into very few error messages and the ones I did see were informative.
    • testapp worked without modifications also on Livelink WebDAV folder.
  • support Compact Framework

The bad:

  • Commercial product
    • You can’t even get evaluation version without registration.
  • Homepage says it is based on RFC 2518 which is an obsolete specification and is marked to be superseded by RFC 4918.
    • Not sure what’s the difference in real world but it is a sign of worry, because RFC 4918 seems to be from June 2007.
  • no xml doc
    • I’m not going to go to their website or open up a separate help-file just to see comments on parameters and to find out that class PropertyName is “WebDAV property name”. I want intellisense so I wouldn’t waste my time!
  • API could be better
    • I could not perform ANY tasks by intuition alone. Not even the “download that file”-task. Even worse – I had to dive into sample application code just to know how to get file size.
  • Code is obfuscated
    • runtime debugging won’t help you much (af.g==false? Oh, really?!)

image

  • default protocol usage is chatty and non-optimal.
    • for example: it queries for all properties when you care only about a few.
    • example of chattiness for the 3 simple tasks (took approx 100 ms)

image

Kommentaare ei ole: