nikkkilll

practical8

Oct 3rd, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. Practical No : 08
  2. Aim : Implement a typical service and a typical client using WCF.
  3. Input :
  4. service.cs:
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Runtime.Serialization;
  9. using System.ServiceModel;
  10. using System.ServiceModel.Web;
  11. using System.Text;
  12.  
  13. namespace WcfService1
  14. {
  15. // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
  16. [ServiceContract]
  17. public interface IService1
  18. {
  19. [OperationContract]
  20. int GetData(int value1,int value2);
  21.  
  22. [OperationContract]
  23. CompositeType GetDataUsingDataContract(CompositeType composite);
  24. // TODO: Add your service operations here
  25. }
  26. // Use a data contract as illustrated in the sample below to add composite types to service operations.
  27. [DataContract]
  28. public class CompositeType
  29. {
  30. bool boolValue = true;
  31. string stringValue = "Hello ";
  32. [DataMember]
  33. public bool BoolValue
  34. {
  35. get { return boolValue; }
  36. set { boolValue = value; }
  37. }
  38. [DataMember]
  39. public string StringValue
  40. {
  41. get { return stringValue; }
  42. set { stringValue = value; }
  43. }
  44. }
  45. }
  46.  
  47.  
  48. service1.svc.cs:
  49. using System;
  50. using System.Collections.Generic;
  51. using System.Linq;
  52. using System.Runtime.Serialization;
  53. using System.ServiceModel;
  54. using System.ServiceModel.Web;
  55. using System.Text;
  56.  
  57. namespace WcfService1
  58. {
  59. public class Service1 : IService1
  60. {
  61. public int GetData(int value1,int value2)
  62. {
  63. return value1*value2;
  64. }
  65.  
  66. public CompositeType GetDataUsingDataContract(CompositeType composite)
  67. {
  68. if (composite == null)
  69. {
  70. throw new ArgumentNullException("composite");
  71. }
  72. if (composite.BoolValue)
  73. {
  74. composite.StringValue += "Suffix";
  75. }
  76. return composite;
  77. }
  78. }
  79. }
Add Comment
Please, Sign In to add comment