A NameValueCollection type cannot be used as a parameter to a Web Method.
For more information on which types can be serialized using XML see
http://msdn.microsoft.com/library/de...ebservices.asp
However, it is easy to achieve similar functionality e.g., by using the
following simple class:
public class NameValues
{
public NameValues()
{}
public NameValues(string name, string[] values)
{
Name = name;
Values = values;
}
public string Name;
public string[] Values;
}
Instead of trying to use a NameValueCollection as parameter you can use an
array of NameValues like so:
[WebMethod]
public void PassNameValues(NameValues[] namesAndValues)
{
foreach (NameValues nameValues in namesAndValues)
{
string name = nameValues.Name;
foreach (string value in nameValues.Values)
{
// ...
}
}
}
Regards,
Sami
"MrDotNet" <Mr******@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
Hi
I want pass NameValueCollection as parameter in webmethod.
I try it but that give me error.
Here is Error.
You must implement the Add(System.String) method on
System.Collections.Specialized.NameValueCollection because it inherits
from
ICollection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.
Exception Details: System.InvalidOperationException: You must implement
the
Add(System.String) method on
System.Collections.Specialized.NameValueCollection because it inherits
from
ICollection.
Thanks
--
-MrDotNet MCAD, MCSD
Sr. Software Engineer / Lead Architect