473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can Pass NameValueCollection as Parameter in WebMethod?

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

Nov 23 '05 #1
2 6809
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

Nov 23 '05 #2
and in general,
if you specify the web service interface using a W3C XML Schema (XSD), you
will always be able to transmit it, in a portable fashion.
This is sometimes called the "Contract First" or "Schema First" approach to
building web services.
For more info on the idea. . .

http://msdn.microsoft.com/vstudio/ja...p/default.aspx

or check out this cool tool from Christian Weyer
http://weblogs.asp.net/cweyer/archiv.../21/39070.aspx

-Dino

"Sami Vaaraniemi" <sa**********@pleasejippii.fi> wrote in message
news:eN**************@tk2msftngp13.phx.gbl...
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


Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Crossley | last post by:
I'm having a type mismatch problem when trying to pass a typed dataset to a web service. My code is: CLIENT CODE I have a dataset schema file called MainData.xsd containing a table called...
2
by: christopherkilmer | last post by:
I've googled my brains out and haven't found the answer yet, so... I have a WebMethod that accepts an array of Order objects as a parameter. I cannot figure out how to send an array to the...
2
by: Jaime Stuardo | last post by:
Hi all.. I have a WebMethod with a parameter defined as DateTime. When I call that webservice, I get this error: System.FormatException: The string '07/24/2005' is not a valid AllXsd value. ...
6
by: placek | last post by:
Hi all. I would like to create two web services: - The first one - ImportData - should take as an input parameter a XML document and return an integer saying if passed XML document was valid...
2
by: ojinfo | last post by:
hi i am currently working on a web service which is supposed to take a xmldocument as input parameter, and then returns another xmldocument. the service is added to the web references in my...
0
by: raghuraman_ace | last post by:
Hi i have started a webservice wich has a webmethod with parameters using literal encoding & encoded encoding . The webservice is compiled successfully . But i don know how to pass the...
5
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into...
14
by: needin4mation | last post by:
I have this in my web service: public XmlDocument GetDataFromDB(string name) { .... do some stuff with name variable..on the database... return the XmlDocument to my datagrid; } Now, in my...
3
by: shapper | last post by:
Hello, I am having some problems in looping through each item in NameValueCollection: 1 Dim a As New NameValueCollection 2 a.Add("My String", City.NewYork) 3 a.Add("My...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.