code_junkie

How do you return a user defined type from a WCF service?

Nov 13th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. using System;
  2. using System.ServiceModel;
  3.  
  4. [ServiceContract]
  5. interface IService
  6. {
  7. [OperationContract]
  8. TimeSpan GetTimeSpan();
  9. }
  10.  
  11. class Service : IService
  12. {
  13. public TimeSpan GetTimeSpan() { return DateTime.Now.TimeOfDay; }
  14. }
  15.  
  16. using System;
  17. using System.ServiceModel;
  18. using System.Runtime.Serialization;
  19.  
  20. [ServiceContract]
  21. interface IService
  22. {
  23. [OperationContract]
  24. Contract GetContract();
  25. }
  26.  
  27. [DataContract]
  28. class Contract
  29. {
  30. [DataMember]
  31. public String MyProperty { get; set; }
  32. }
  33.  
  34. class Service : IService
  35. {
  36. public Contract GetContract() { return new Contract(); }
  37. }
Add Comment
Please, Sign In to add comment