Search code examples
c#.netwcfwsdldatacontract

Is it possible to include a DataContract class in WCF wsdl without that class being part of any OperationContract?


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


Solution

  • 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.