0

I have have a WCF service with a PostData operation contract. This method takes in a string. This string should be one of 3 objects seriazlised. I have created 2 classes for these objects and decorated them with [DataContract] and [DataMembers].

Because I do not reference these classes in the PostData Operation contract, they are not showing up in the WSDl. Inwould like the client to be able to create an instance of one of these classes and then pass the serialised object in the PostData. This would save me from creating 3 distinct OperationContracts.

Is this possible?

THanks

  • Sounds pretty unusual, why not just use the type in the parameter instead of serializing it first – TheGeneral Oct 09 '18 at 08:59
  • I have 3 different types that can be passed in. That means having 3 PostData functions taking a different type. I will have other service methods too so anytime I add a method, I'll need to add 3 – TheGrizzlyOne Oct 09 '18 at 09:06
  • "3 different types that can be passed in" is by itself a strange design. Avoid it when you can. In lieu of that, add a dummy method that references your types. – bommelding Oct 09 '18 at 10:21
  • This maybe will help you: https://stackoverflow.com/questions/37415505/how-to-return-a-listobject-in-wcf/51476191#51476191 – Dani Oct 09 '18 at 13:55

1 Answers1

0

So what I have decided on here.

There are 3 types that the client could serialise and pass to the single Web method. I have provided these 3 types in a shared dll. The client creates an object of one of these types, serialises and passes it through to the web service along with an Enum parameter. This Enum allows the web service to deserialise the string back to the appropriate type and carry on processing.

This reduces the workload on the web service side as instead of having to write a web method for each type, I can just require a single method.

This may help someone else who wishes to address a similar issue.