c# - Writing overloaded web service methods -


i have web service method following signature.

[webmethod] public void start(string application, string version){} 

due additional requirements, method has receive additional parameters @ same time support other clients not have latest version yet. ended writing 2 overloaded methods

[webmethod(messagename="start", description="start", enablesession=true)] public void start(string application, string version){}  [webmethod(messagename="startv2", description="startv2", enablesession=true)] public void start(string application, string version, string exception){} 

with scenario, ended writing duplicate code. code in startv2 method same start additional code processing additional parameters.

in near future, believe additional parameters added again , need write overload method again.

is there way write without duplicating codes?

you have single method optional parameters, webmethods can call so:

[webmethod(messagename="start", description="start", enablesession=true)] public void start(string application, string version){     starthandler(application, version); }  [webmethod(messagename="startv2", description="startv2", enablesession=true)] public void start(string application, string version, string exception){     starthandler(application, version, exception); }      private void starthandler(string application, string version, string exception = null) {} 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -