Web Service COM wrapper dnd *.dll.config

A

Al Reid

I created a COM wrapper around a .NET web service using VB2005. It is intended to be a common component in a system that is to be
distributed to multiple customers. Each customer will host their own instance of the web service and they will each have a
different URL to the web service. I want to avoid having to compile a version of the DLL for each customer. VB2005 generates a
*.dll.config file that contains the URL to the web service, but it doesn't seem to be read when the DLL loads.

Is there some way to force the DLL to load the settings from the *.dll.config file OR is there another better or more reliable
method of reading the URL and using it to connect to the web service?

TIA,
 
A

Al Reid

Why should this be so hard? I don't have an answer to that, but I did find a temporary work-around that I don't feel completely
comfortable with.

I created my own XML configuration file that I will distribute with the COM dll that contain the web reference. I then manually
edited the settings.designer.vb file to make the existing entry for the dynamic web reference read/write. I then coded a class to
retrieve the setting from the custom xml file and to write the setting to the my.settings.xxxx setting. The new setting is then
automatically used when I create the reference to the web service.

I would have preferred finding a way to just load the *.dll.config file, but so far no luck.

I'll continue to monitor this thread for a while and hope that there is someone with an answer.

Thanks,
 
M

Michel Posseth

Al Reid said:
Why should this be so hard? I don't have an answer to that, but I did
find a temporary work-around that I don't feel completely
comfortable with.

I created my own XML configuration file that I will distribute with the
COM dll that contain the web reference. I then manually
edited the settings.designer.vb file to make the existing entry for the
dynamic web reference read/write. I then coded a class to
retrieve the setting from the custom xml file and to write the setting to
the my.settings.xxxx setting. The new setting is then
automatically used when I create the reference to the web service.

I would have preferred finding a way to just load the *.dll.config file,
but so far no luck.

I'll continue to monitor this thread for a while and hope that there is
someone with an answer.

Thanks,

I solved it with this class that i include in all my dll projects

Imports System.Configuration
Namespace My
Partial Friend NotInheritable Class MySettings
Private DllSettings As ClientSettingsSection
Private DllConfigDoesNotExist As Boolean
Default Public Overrides Property Item(ByVal propertyName As String)
As Object
Get
Dim oValue As Object = Nothing
Try
'If the .dll.config file has already been loaded, use it
to obtain the value...
If DllSettings IsNot Nothing Then
oValue =
DllSettings.Settings.Get(propertyName).Value.ValueXml.InnerXml
ElseIf Not DllConfigDoesNotExist Then
If Me.LoadDllConfigFile() Then
oValue =
DllSettings.Settings.Get(propertyName).Value.ValueXml.InnerXml
End If
End If
Catch ex As Exception
End Try
Try
If oValue Is Nothing Then
oValue = MyBase.Item(propertyName)
End If
Catch ex As Exception
End Try
Return oValue
End Get
Set(ByVal value As Object)
MyBase.Item(propertyName) = value
End Set
End Property
Private Function LoadDllConfigFile() As Boolean
Dim bDllConfigLoaded As Boolean = False
Dim cfgDll As System.Configuration.Configuration
Dim cfmDllCfg As New ExeConfigurationFileMap()

Dim sAssemblyPath As String =
Reflection.Assembly.GetExecutingAssembly().Location

Dim strNamespace As String = GetType(MySettings).FullName
strNamespace = strNamespace.Substring(0,
strNamespace.IndexOf("."c))


cfmDllCfg.ExeConfigFilename = sAssemblyPath & ".config"
Try

cfgDll =
ConfigurationManager.OpenMappedExeConfiguration(cfmDllCfg,
ConfigurationUserLevel.None)

Dim csgApplicationSettings As ConfigurationSectionGroup =
cfgDll.GetSectionGroup("applicationSettings")
Me.DllSettings =
DirectCast(csgApplicationSettings.Sections(strNamespace & ".My.MySettings"),
ClientSettingsSection)
bDllConfigLoaded = True

Catch ex As Exception

'bestaat niet
DllConfigDoesNotExist = True

End Try
Return bDllConfigLoaded

End Function

End Class

End Namespace



HTH

Michel Posseth
 
A

Al Reid

Thanks, Michael. I'll take a good look at this. At a glance, it looks to be exactly what I need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top