-1

AFAIK:

Adding an optional parameter to a public method that’s called from another assembly requires recompilation of both assemblies— just as though the parameter were mandatory.

I was wondering about WebService in this context.

What about me - using an added optional param webservice method?

for example :

lets say Google's webservice method was :

void DoWork(int a , int b)

and it was changed to

void DoWork(int a , int b  , isDefault=false)
  • must I , as a consumer need to recreate the proxy file ?
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
  • I think you have to recreate. I have created a web service (SOAP) and at some time I just changed the case of the letters of the parameters. My client stopped working and had to recreate proxy. For test calling SOAP web services you can download SoapUI (http://www.soapui.org/). It's very handy at times. – alfoks Dec 10 '12 at 12:35
  • I think you need to specify the exact API being used for this to be answerable. Note that Google won't specify its APIs in C#. – H H Dec 10 '12 at 12:38
  • Google was just an example of "code I can't touch". I could have asked it : "If my friend build a webservice and which takes only 2 param , and then after a month he adds an optional prameter...should I recreate...." – Royi Namir Dec 10 '12 at 12:50
  • @RoyiNamir how is your proxy being generated - are you running a tool like xsd.exe over a WSDL, or adding a Web Service reference via Visual Studio, or by some other means? – Chamila Chulatunga Dec 10 '12 at 13:08

1 Answers1

3

My understanding is that optional parameters are syntactic sugar.

You still end up with an overload that takes all parameters as mandatory, however the compiler will automatically insert the default for the optional parameter into the call site in the IL when it encounters a method call without the optional parameter specified.

How this affects Web Services depends on how the optional parameter is propagated through the proxy.

If it is a non-breaking change to the WSDL, then my guess is that it won't make a difference, where you won't need to regenerate the proxy, and the requests generated by the existing proxy will still be valid from a WSDL contract point of view.

However, if it is a breaking change to the WSDL, then you would obviously need to regenerate the proxy, and any call sites into proxy methods would need to be recompiled.

Chamila Chulatunga
  • 4,856
  • 15
  • 17
  • 1
    _If it is a non-breaking change to the WSDL, then my guess is that it won't make a difference_ **VS** _however it is a breaking change to the WSDL, then you would obviously need to regenerate the proxy_ **Thanks but** you provided the _options_. which are already known. I think I need an answer. – Royi Namir Dec 10 '12 at 12:40
  • Sorry, I may have been confusing there - I meant to say "if it is a breaking change...". Updated in edit. And to know whether it is or isn't a breaking change, can you explain how you are generating the proxy? I'm assuming from a WSDL, but maybe not? – Chamila Chulatunga Dec 10 '12 at 12:41