Is there a way to return different types from a WCF REST method?

I am trying to write a web service for a specification, and this requires a different response body, depending on whether this method completed successfully or not. I tried to create two different DataContract classes, but how can I return them and are they serialized correctly?

+5
source share
3 answers

The answer is yes , but it is difficult and you lose strong typing on your interface. If you return the stream , then the data can be xml, text, or even binary. For the DataContract classes, you then serialize the data using the DataContractSerializer .

BlogSvc RestAtomPubService.cs WCF . , , WCF, .

+1

, - WCF , - FaultException. web.config , .

. . KnownType, , . , , Object , .

, , , , , . Silverlight 2, Beta 2 . , , , , , ...

ADO.NET Data Services, .

FaultContracts

+2

xml, , . , , - . JSON , , . ( ), , JavaScriptSerializer , .

0

All Articles