views:

18

answers:

1

I've just started to use VS2010 and with it comes c# 4.0.

I have since been using the default values for some of my methods, which has allowed me to remove some overloads that performed this operation.

My problem is as follows:

I have a library project that has several classes that I use for various things throughout several other projects. The default values work well here.

Another project is a web service that I use to perform some tasks on a remote server. No errors are shown (or warnings) when I compile this project that the above methods won't work. It compiles fine.

However, when I add this service to another project as a Service Reference, it doesn't seem to see that the method has default values and so complains I am not supplying enough arguments.

I re-deployed my service and updated the service reference, but it is still the same. I also just noticed that a previously working method that uses an 'out' argument (i.e.e MyMethod(out String arg1, String arg2)) doesn't seem to work either now.

Any suggestions? I'm not aware that I have changed any config settings that would do this, so I assume it must be C# 4.0. Having said that, the out argument was working with 4.0 last week :S

Thanks for any help offered...

Cheers Neil

A: 

I wouldn't be surprised to hear that default values specified in a web service aren't reflected in the proxy code generated by Visual Studio. You could create your own proxy layer of course, which would be very simple - but you'd need to update it every time you changed the web service.

If you have a look at the WSDL for your service, does that indicate the default values? It could also be that there's a switch somewhere in the generator to generate optional parameters or not (for compatibility with C# 3).

The out parameter is potentially a different matter entirely - what error are you getting?

Jon Skeet
The error I see is similar, this is the one for the out parameter:Method 'MyMethod' has 2 parameter(s) but is invoked with 3 argument(s)As I said, I'm sure this particular one wasn't a problem previously, so it could be something silly!
neildeadman
@neildeadman: Hmm... that sounds very strange (note that it's too *many* arguments rather than too few). What does the generated code look like?
Jon Skeet
With the help of a colleague, we have got to the bottom of the 'out' parameter. I have to say I don't like the fact that Visual Studio or C# did this with no mention of it happening to myself.I changed said method from returning a Boolean to a void. C# (lets say) then made it so the service returned a string, the out parameter.We assume its because returning a value is more efficient than using out parameters.Curiously, we found a post to someone having the complete opposite issue. A return value was made into an out parameter in their service!
neildeadman