Returning a ConfigurationElement from a Web Service

R

Robert Scheer

Hi.

I wrote some classes to deal with custom sections on my .config file.
The classes work ok when called directly from my application, but when
I call these classes from a Web Service I keep receiving the error:

"You must implement a default accessor on
System.Configuration.ConfigurationLockCollection because it inherits
from ICollection."

But my class has a default acessor. My classes are as follow:

Public Class ClientsCollection
Inherits ConfigurationElementCollection

Protected Overloads Overrides Function CreateNewElement() As
ConfigurationElement
Return New ClientDefinition
End Function

Protected Overrides Function GetElementKey(ByVal element As
ConfigurationElement) As Object
Return DirectCast(element, ClientDefinition).Name
End Function

Public Shadows ReadOnly Property Count() As Integer
Get
Return MyBase.Count
End Get
End Property

Public Sub Add(ByVal value As ClientDefinition)
BaseAdd(value)
End Sub

Default Public Shadows ReadOnly Property Item(ByVal Name As
String) As ClientDefinition
Get
Return CType(BaseGet(Name), ClientDefinition)
End Get
End Property

Default Public Shadows Property Item(ByVal index As Integer) As
ClientDefinition
Get
Return CType(BaseGet(index), ClientDefinition)
End Get
Set(ByVal value As ClientDefinition)
If BaseGet(index) IsNot Nothing Then
BaseRemoveAt(index)
End If

BaseAdd(index, value)
End Set
End Property
End Class

Public Class ClientDefinition
Inherits ConfigurationElement

<ConfigurationProperty("name", IsRequired:=True)> _
Public Property Name() As String
Get
Return CType(Me("name"), String)
End Get
Set(ByVal value As String)
Me("name") = value
End Set
End Property

<ConfigurationProperty("connectionString", IsRequired:=True)> _
Public Property ConnectionString() As String
Get
Return CType(Me("connectionString"), String)
End Get
Set(ByVal value As String)
Me("connectionString") = value
End Set
End Property
End class


And the WebMethod as follows:

<WebMethod()> _
<XmlInclude(GetType(ClientsCollection))> _
<XmlInclude(GetType(ClientDefinition))> _
Public Function GetNativeConfiguration(ByVal key As String) As
ClientDefinition
Dim mgrClient As ClientsDefinitionManager = Nothing
Dim dcClient As ClientDefinition = Nothing

Try
mgrClient = New ClientsDefinitionManager(Server.MapPath
("~"), key)
dcClient = mgrClient.Find(key)
Return dcClient

Catch exError As Exception
Throw
End Try
End Function

Am I missing something?

Regards,
Robert Scheer
 

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

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top