vendredi 30 novembre 2018

Design dynamic grouping of wcf service response attributes based on input request c#

Below is a sample format of response and equivalent service contract of my web service looks like.

<Players>
 <Player>
     <Name>Sachin</Name>
     <Sport>Cricket</Sport>
     <SportType>Team Game</SportType>
 </Player>
 <Player>
     <Name>Ronaldo</Name>
     <Sport>Football</Sport>
     <SportType>Team Game</SportType>
 </Player>
 <Player>
     <Name>Alfred</Name>
     <Sport>Shooting</Sport>
     <SportType>Individual</SportType>
 </Player>
</Players>

Now UI team is asking for new feature where they want grouping logic of different fields in service. For example in input request in newly exposed 'groupBy' field they can send can send field name "Sport" and then they want Player element grouped by "Sport" in response and same is possible for "SportType".

<SportTypes>
    <SportType>
        <Type>Team Game</Type>
        <Players>
            <Player>
                <Name>Sachin</Name>
                <Sport>Cricket</Sport>
            </Player>
            <Player>
                <Name>Ronaldo</Name>
                <Sport>Football</Sport>
            </Player>
        </Players>
    </SportType>
    <SportType>
        <Type>Individual</Type>
        <Players>
            <Name>Alfred</Name>
            <Sport>Shooting</Sport>
        </Players>
    </SportType>
</SportTypes>

I don't have problem grouping the fields after retrieving them from database but I don't know how can I define service contract for dynamic service response as response structure will change after grouping.For some very odd(maybe stupid) reasons UI team doesn't want to do this grouping so it has to be done in service. Maybe I am approaching the problem in wrong way.Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire