Thursday, 15 May 2014

c# - How to let user decide which service to request in WCF? -



c# - How to let user decide which service to request in WCF? -

in wcf how allow user decide service request when inquire 2 values , have ability perform different calculations values.

for illustration inquire value1 , value 2. , user have selection perform addition, subtraction , multiplication values.

how can accomplish that?

[operationcontract] int gettwovalues(int value1, int value2); public int addition(int value1, int value2){ homecoming value1+value2; } public int subtraction(int value1, int value2){ homecoming value1-value2; }

how logic

if user.request="addition"{ add-on } else if user.request="subtraction"{ subtraction }

i know not code have written trying have understanding of saying. help appreciated.

not quite sure understand question

[operationcontract] public int subtraction(int value1, int value2) { homecoming value1 - value2; } [operationcontract] public int addition(int value1, int value2) { homecoming value1 + value2; }

would work like

[operationcontract] public int calculation(int value1, int value2, string calctype) { switch (calctype) { case "addition": homecoming value1 + value2; case "subtraction": homecoming value1 - value2; } //return default or throw exception }

not either without drawbacks of course, both meet criteria.

edit: comment raises obvious point switch case allows user perchance supply value doesn't map.

yes , wouldn't utilize strings, example!

possible ways round it?

validate user input - allow them know when provide isn't valid use default throw exception use enum forcefulness user select pre defined list similarly utilize first method

i think perhaps need explain more in question want achieve.

c# .net windows wcf communication

No comments:

Post a Comment