C# Service Reference Configuration - Much Confused

etienne_marais

Honorary Master
Joined
Mar 16, 2008
Messages
16,250
Reaction score
19,740
Location
Centurion
I have a C# Windows Forms application [client] which consumes a C# webservice. The Windows Forms application's reference to the webservice is configured for Collection Type as System.Collections.Generic.List as the webservice returns structures containing lists and also has methods with parameters of type List<T>.

Today I added two methods to the webservice, I updated the service reference in the client and some 90 odd errors popped up. I commented out the two methods in the webservice and ran the service update again, same problem.

All the errors are related to List<T> versus T[] (array of Type)

Just to check, I reconfigured the service reference's collection type to Array and even ArrayList, and then back to List again. No go.

Here is an example:

In the webservice is defined:

Code:
public class ParameterSet
{
     public List<Parameter> Parameters = new List<Parameter>();
}

In the client I have:

Code:
MyWebServiceReference.ParameterSet parameterSet = new MyWebServiceReference.ParameterSet();
parameterSet.Parameters = new List<MyWebServiceReference.Parameter>();

which used to work fine until that service reference update.

The compile error is on the second line:

" Cannot convert List to [] "

To fix this:
Code:
parameterSet.Parameters = new MyWebService.Parameter[n];

but that requires a value for n which is not known before runtime.

What the hell happened ?

Funny enough, this coincided with a Windows 10 update(s), don't know if it is related or not.
 
Last edited:
Doubt it is related to win 10.

Have you completely removed and re-referenced the service?
 
Doubt it is related to win 10.

Have you completely removed and re-referenced the service?

Will try tomorrow, all I have tried was closing the IDE (&rebooting) as I have had some anomalies before resolved this way, thanks for advice :D
 
For the array list, try ArrayList parameters = new ArrayList();

Just a quick Google, never coded in C# before.


EDIT:
I think the issue is that it doesn't know how large the list is, then you convert it into a fixed number array. So you could also try to get length and use a for loop to convert? Would be less efficient though.

EDIT2: Take whatever I say with a salt shaker, haven't coded for very long.
 
Last edited:
For the array list, try ArrayList parameters = new ArrayList();

Just a quick Google, never coded in C# before.


EDIT:
I think the issue is that it doesn't know how large the list is, then you convert it into a fixed number array. So you could also try to get length and use a for loop to convert? Would be less efficient though.

EDIT2: Take whatever I say with a salt shaker, haven't coded for very long.

Thanks for trying to help, but I'll go for the salt shaker :D
 
When you generate the service reference there is an option to use arrays or list of T
 
You're going to need to be specific about those error messages.

For the example given:
parameterSet.Parameters = new List<MyWebServiceReference.Parameter>();

" Cannot implicitly convert type 'System.Collections.Generic.List<MyServiceReference.Parameter>' to 'MyServiceReference.Parameter[]' "

The LHS is interpreted as an array rather than the List<Parameter> as defined in the webservice, and the collection type is indeed set to List in the service reference configuration. And this is how the webservice/client has been used for many months. I think my VS is broken.
 
Last edited:
For the example given:




The LHS is interpreted as an array rather than the List<Parameter> as defined in the webservice, and the collection type is indeed set to List in the service reference configuration. And this is how the webservice/client has been used for many months. I think my VS is broken.

Post a screen shot of the options you select for the generation of the reference. Your reference.cs looks very broken.
 
Another example:

DateTime startDate = (DateTime)(parameterSet.Parameters.Find((parameter) => { return (parameter.Name == "StartDate");}).Value);

Here parameterSet.Parameters is again interpreted as an array rather than a List. There error is:
" no overload for method 'Find' found taking 1 argument. "

It is not using the List.Find method, it is apparently trying to use something else.
 
Last edited:
For the example given:




The LHS is interpreted as an array rather than the List<Parameter> as defined in the webservice, and the collection type is indeed set to List in the service reference configuration. And this is how the webservice/client has been used for many months. I think my VS is broken.



what part of

When you generate the service reference there is an option to use arrays or list of T

did you not understand?
 
what part of



did you not understand?

Read the OP, I am using List for Collection Type under service reference configuration. In VS 2010 the reference is generated after supplying a URL and after its done you change the collection type which modifies the reference.
 
I see its an asmx. Remove your reference and add it under web references.

Ah, now that is interesting.

I usually add the reference under 'service references' and then it automatically lies beneath 'web references' ( you can't add directly to web references, if you right-click there is no add option there ). We may be one step closer as it seems to be in the wrong place ?
 
Ah, now that is interesting.

I usually add the reference under 'service references' and then it automatically lies beneath 'web references' ( you can't add directly to web references, if you right-click there is no add option there ). We may be one step closer ?

It wont automatically go under service references, a service reference is for wcf references. Web Reference is for legacy stuff that uses asmx and soap and ****.
 
It wont automatically go under service references, a service reference is for wcf references. Web Reference is for legacy stuff that uses asmx and soap and ****.

These are the options when I right-click on web references:

scr2.png

(but right-clicking on 'service reference' allows me to add)
 
Top
Sign up to the MyBroadband newsletter
X