Search code examples
c#wcfweb-servicesdatacontract

Creating a DataContract for an external object


I'm currently developing a WCF Web Service in C#.NET. I'm fairly new to this. I'm thinking about how a certain method should be implemented, because it needs to return an "external" object as a DataContract. I'm not sure how this works.

My Web Service implements another 3rd party Web Service. The reason for this is because we are not allowed to expose all methods and data to the public. So we're designing a Web Service that strips out certain data and methods that the 3rd party Web Service exposes.

The 3rd party Web Service exposes a method like this:

CourtVerdictResults GetVerdict ( CourtVerdictRequest verdict );

My Web Service implements a stripped down version of that method like so:

CourtVerdictResults GetVerdict ( String verdictCaseNumber );

In that method i then strip out some sensitive data and after that i should return the CourtVerdictResults object.

But this object is defined in the 3rd party Web Service. My project references that Web Service so it knows about that object. But my own Web Service doesn't have that object as a DataContract. So how can i return such an object when others start to use my Web Service?

Do i need to do something special, so that when others implement my Web Service, that their code knows about the CourtVerdictResults automatically?


Solution

  • You can make your own CourtVerdictResults class (in a different namespace or the names will clash) that is the same as the third party object (or as same as you want it to be).

    Retrieve the 3rd party object from their service, map it's values to your object (trivial if using ValueInjector or something similar) and then return your object.