Hi all,
I've been building a nifty deserializing configuration handler that I use in
conjunction with my web.config in an ASP.NET web app. This is working quite
well, but I'm planning on servicing a number of different web service
operations from a single application, and because it's all XML, I've been
scoping everything to a specific namespace targeting a specific application
(these are all InfoPath forms).
It seems that the GetConfig method can only refer to a node by it's
local-name:
ConfigurationSettings.GetConfig("AccountsInRole");
What I would like to do is pass in a namespaceURI as well, so that I can use
the same node local-name for a number of applications, each with their own
section. Like:
ConfigurationSettings.GetConfig("AccountsInRole",
"urn:schemas-rdcpro-com:infopath/application1");
While I can specify a namespace in my ConfigurationSectionHandler, and use
namespace-qualified nodes, I don't see a way to specify that externally (ie,
from the calling web app):
public class XmlSerializerSectionHandler : IConfigurationSectionHandler
{
public object Create(object parent, object configContext, XmlNode section)
{
XPathNavigator xmlNav = section.CreateNavigator();
XmlRootAttribute xmlRoot = new XmlRootAttribute();
// wish I could explicitly set the Namespace I want!
xmlRoot.Namespace = xmlNav.NamespaceURI;
xmlRoot.ElementName = (string) xmlNav.LocalName;
string typeName = (string) xmlNav.Evaluate("string(@type)");
Type myType = Type.GetType(typeName);
XmlSerializer sr = new XmlSerializer(myType,xmlRoot);
// This will be cast to the appropriate type in the calling code.
return sr.Deserialize(new XmlNodeReader(section));
}
}
Of course, I could make my configuration a little more general, and have
nested custom configuration sections like:
<FormSubmitService>
<Application1>
<AccountsInRole type="ApplicationRoles.Accounts, ApplicationRoles">
<!-- config info for App 1 here -->
</AccountsInRole>
</Application1>
<Application2>
<!-- config info for App 2 here -->
</Application2>
and get the right one with:
ConfigurationSettings.GetConfig("FormSubmitService/Application1/AccountsInRole");
But it seems a shame to have XML Namespaces, and not be able to use them!
;^)
Am I missing something here? How would I get a particular "AccountsInRole"
using an XML namespace?
Regards,
Mike Sharp