Thursday, July 14, 2005

Passing SortedList via WebServices [Q&A]

Classes which implements IDictionary are very useful for developers. Concept of key - value addressing could be applied in many areas, including web services.
however, when you try to return a SortedList, ListDictionary or Hashtable from webservice you get run-time error when accessing web service:

System.NotSupportedException: The type System.Collections.SortedList is not
supported because it implements IDictionary.

Cheapest server side solution is to return array of DictionaryEntry filled by SortedList.CopyTo method. Sample code is :
[WebMethod]
public DictionaryEntry[] HelloWorld()
{
SortedList sl = new SortedList();
sl.Add("Key","Value");
DictionaryEntry[] deArray = new DictionaryEntry[sl.Count];
sl.CopyTo(deArray, 0);
return deArray;
}
And on client side you need to create SortedList and fill it manually.
Please note, that you can export entries from one list and add it to another. For example, server can use HashTable for better performance and client SortedList in order to display items ordered for end user.

Applies to all dotnet languages: C#, VB.NET, C++.NET, J#
Idea of this topic was suggested by google search engine.

Wednesday, July 13, 2005

Oracle Developer Tools for Visual Studio .NET [News]

Oracle corporation informs about Oracle(R) Developer Tools for Visual Studio .NET 2003.

This is free plug-in that enables developers to use Microsoft Visual Studio .NET 2003 to develop and deploy Oracle Database 10g applications on Microsoft Windows. This plug-in integrates Oracle Database 10g and Visual Studio .NET 2003 and reinforces Oracle's commitment to meet the needs of the Windows development community.

Oracle Developer Tools for Visual Studio .NET 2003 is available today for download from the Oracle Technology Network at: http://www.oracle.com/technology/tech/dotnet/tools/index.html . (187MB)

Oracle's support for the Windows development community extends beyond Oracle Developer Tools for Visual Studio .NET 2003. Oracle Database 10g Release 2 incorporates new features that further Oracle's commitment to Windows application developers. Release 2 includes Oracle Database Extensions for the .NET Framework, offering improved Microsoft .NET Framework support via stored procedures implemented using Common Language Runtime (CLR). The new feature enables developers to write .NET Framework-based stored procedures and deploy them into Oracle Database, helping to reduce the time it takes to build and deploy .NET Framework-based applications. Oracle Database 10g Release 2 for Windows is scheduled for availability in the next 90 days.

Other Oracle products for the .NET Framework, visit the .NET Developer Center on the Oracle Technology Network at http://www.oracle.com/technology/tech/dotnet/ .

Monday, July 04, 2005

ReadOnly SortedList [Coding]

Overview

It's common task to hold information in some kind of array or collection and provide user's of your component with read only access. For example we have ArrayList.ReadOnly(ArrayList list) for System.Collection.ArrayList. It creates read only array wrapper for you data. However, we do not have same feature for sorted list, which is also very good for storing internal data.

Implementation

SortedList have virtual property bool ReadOnly which always return false by default. When we override it, we will have possibility to control this feature.
In current implementation I've implemented 2 methods - LockReadOnly and UnlockReadOnly, which change state of ReadOnly property. To ensure that only correct code able to change list, Lock return a random key which is required to unlock a list.

Sources here [4k], written on C#.

Applies to all dotnet languages: C#, VB.NET, C++.NET, J#

Custom files in Assembly [Coding]

Custom files in Assembly


Main dificulty with placing files in assembly and reading it is namespaces.
Path to your file consist from:
  • Default Namespace from project properties
  • Folder structure in project
  • filename itself

To divide folders and namespaces, '.' (dot) is used.

Warning: When you change default namespace in project properties, filename folder will be changed immediately in compilation

Full source code (reading text file from assembly) is here [5K].

Main lines are:

private const string RESOURCE_NAME = "Folder.resource.txt";

System.Type type = typeof(Class1);
Stream stream = type.Assembly.GetManifestResourceStream(type, RESOURCE_NAME);
if (stream == null)
throw new Exception("System could not load resource");
OR

stream = Assembly.GetAssembly(typeof(Class1)).GetManifestResourceStream(typeof(Class1).Namespace + "." + RESOURCE_NAME);

Applies to all dotnet languages: C#, VB.NET, C++.NET, J#