Home
english
Home
WebDAV Server
WebDAV Client
WebDAV AJAX
Map Drive
Pricing
News
Contacts
info@ithit.com



Creating Class 1 WebDAV Server

Engine Class

To create Class 1 WebDAV Server you will have to implement IFolder, IResource, IResponce interfaces and create 2 classes derived from Request and Engine. Here is typical WebDAV server class hierarchy in your program for Engine, Request and IResource implementation:

The core component of WebDAV Server library is the Engine class. It parses WebDAV XML requests and generates XML output. Here is typical engine workflow for each request:

1. Create separate Engine instance for each request. Create Request and Response instances.
2. Call Engine.Run() method.
3. Engine calls Engine.License get.
4. Engine calls Engine.GetHierarchyItem()
5. Engine calls members of interfaces IFolder, IResource, ILock etc.

The Run method of the Engine class has 2 parameters that pass all necessary input and output information making the engine independent of the hosting environment. The first parameter – Request class is a simplified analogue of HttpRequest in ASP.NET and second IResponse analog of HttpResponse class. You will create 2 classes derived from Request and IResonse. The implementation is usually simple and straightforward. You will directly call properties and methods of underlined HttpRequest / HttpResponse or HttpListenerRequest / HttpListenerResponse classes:

public class MyRequest : Request

{

...

  public override string ContentType

  {

    get{ return HttpContext.Current.Request.ContentType; }

  }

...

}

Here is how simple requests processing cycle in your program will look like:

HttpListener listener = new HttpListener();

listener.Prefixes.Add("http://localhost:8080/");

listener.Start();

while (true)

{

  // your class derived from Endine class

  WDEngine engine = new WDEngine();

  HttpListenerContext context = listener.GetContext();

  // your class derived from Request class

  WDRequest request = new WDRequest(context.Request, context.User);

  // your class that implements IResponse interface

  WDResponse response = new WDResponse(context.Response);

  engine.Run(request, response);

  context.Response.Close();

}

For the sake of simplicity this code process only one request at a time and will block while waiting for a client request. Usually you will utilize more complex asynchronous model, that does not block while waiting for requests and each request is processed in its own execution thread.

HttpListener class is provided with .Net Framework 2.0. If you need to create WebDAV Server based on .Net Framework 1.x you will have to host you server in IIS and create class derived from IHttpHandler. More about this topic could be found here: Hosting WebDAV Server in IIS

Other important data required by engine is information about objects in your storage and its hierarchy. To provide Engine with this data you will have to create your class derived from Engine class and implement GetHierarchyItem method. Engine calls this method while processing requests and passes the path of the required object. In GetHierarchyItem method you will be searching your repository and return requested object.

Storage Hierarchy Items

There are 2 types of objects in a Class 1 WebDAV repository: folders, represented by IFolder interface and resources represented by IResource interface. Both IFolder and IResource are derived from IHierarchyItem interface.

Most of IHierarchyItem interface members are self explanatory and represent properties and methods that each folder and resource has, such as name of the item, creation and modification date, methods required to copy and move the item.

Note: Microsoft WebDAV Client requires that, creation and modification date of the item to be in Universal Coordinated Time (UTC) format.

In addition to IHierarchyItem methods and properties IResource interface has 4 more members specific for resources: methods for getting MIME type of the resource (ContentType), length of the resource content in bytes, and methods for reading and writhing resource content.

IFolder interface has a property for enumerating its children and methods for creating resource and folder.

Response Interfaces

Most IT Hit WebDAV Engine interfaces methods return classes derived from WebDAVResponse class. This is required to inform WebDAV client about the result of the operation. WebDAVResponse class is converted to XML by the Engine and send to a WebDAV client. Often it is required to return different responses depending on how the operation competed. For instance simple CopyTo implementation checks if the item with destName exists and returns CreatedResponse or NoContentResponse:

public virtual WebDAVResponse CopyTo(IFolder folder, string destName, bool deep)

{

...

WebDAVResponse resp;

if (/*no item with destName*/)

{

// copy item

...

resp = new CreatedResponse();

       }

       else // update existing item

{// update item

...

       resp = new NoContentResponse();

}

return resp;

}

WebDAV Server Engine class reference provides information what type of responses you should return from each method depending on the result of the operation.

To provide WebDAV client with more information about each item operation result when processing trees in CopyTo, MoveTo and Delete implementations of IFolder you can return instance of MultistatusResponse class. MultistatusResponse is derived from WebDAVResponse and allows specifying what items failed to move copy or delete. MultistatusResponse has AddResponses method for adding errors specifying URL of the resource and its status.

Hierarchy Item Properties

Each item in a repository could have string properties associated with the item. Each property is represented by Property structure and has Name, Namespace, and Value. For manipulating string properties IHierarchyItem provides GetProperties and UpdateProperties methods. Engine calls GetProperties passing the list of properties requested by client or null if all properties are requested. In your implementation you will populate the list passed by reference to this method or create the new list and return it to the engine (see example of GetProperties implementation).

In your UpdateProperties implementation you will create, modify and delete string properties. If any property failed to update than you should not modify any properties and rollback the entire operation. To inform WebDAV client which properties failed to update you must return MultipropResponse class instance. Each item of MultipropResponse contains the information about individual property update operation (see example of UpdateProperties implementation).

Microsoft Office, Windows Vista Web Folders and WebDAV

Your Class 1 server will not support saving directly from Microsoft Office applications as well saving files from Windows Vista Web Folders client. To publish Office documents to your WebDAV Server using File Open and File Save and grag-and-drop files on Vista you mast create WebDAV Class 2 complaint server. Before modifying any items on a WebDAV server this applications issue lock commands to prevent documents overrighting by other users.

To support class 2 you must inherit your resource and folder class from ILock and IFolderLock as well as implement lock-null items with ILockNull interface. However if you do not need the fully functional Class 2 server you can provide simplified implementation of ILock interface:

public LockInfo[] ActiveLocks

{

  get

  {

    LockInfo[] lockInfo = new LockInfo[1];

    lockInfo[0].Token = Guid.Empty.ToString();

    lockInfo[0].Shared = true;

    lockInfo[0].Deep = false;

    lockInfo[0].Owner = "Name";

    return lockInfo;

  }

}

 

public WebDAVResponse Lock(ref LockInfo lockInfo)

{

  lockInfo.Token = Guid.Empty.ToString();

  return new OkResponse();

}

 

public WebDAVResponse RefreshLock(ref LockInfo lockInfo)

{

  lockInfo.Shared = true;

  lockInfo.Deep = false;

  lockInfo.Owner = "Name";

  return new OkResponse();

}

In this case your server will not protect against items modifications but will be accessible from Microsoft Office applications and Windows Vista Web Folders client. However you still will have to implement ILockNull and IFolderLock interfaces.

See Also:


What WebDAV software would you like to have?

Selected Customers:
Country: Norway
DnB NOR Group
Country: Finland
Bank of Finland
Country: United Kingdom
Bechtle Direct
Country: Sweden
BT Industries
Country: USA
California Chamber of Commerce
Country: Denmark
Danfoss Group
Country: Denmark
DFDS
Country: USA
Fluke Networks
Country: USA
HNI Corporation
Country: USA
IHS Inc
Country: USA
LandAmerica Financial Group
Country: Canada
Laurentian University
Country: USA
Microsoft
Country: Israel
RADVISION
Country: Ukraine
Raiffeisen Bank
Country: Netherlands
Sanoma Uitgevers
Country: USA
Siemens
Country: Australia
WorkCover NSW
Country: Ukraine
OTP Bank
Country: USA
Intel Corporation
Country: Austria
Austrian Federal Railways
Home WebDAV Server WebDAV Client