Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <configuration>
  3. <system.serviceModel>
  4. <services>
  5. <service name="WcfService3.Service1" behaviorConfiguration="WcfService3.Service1Behavior">
  6. <!-- Service Endpoints -->
  7. <endpoint address="" binding="wsHttpBinding" contract="WcfService3.IService1">
  8. <identity>
  9. <dns value="localhost"/>
  10. </identity>
  11. </endpoint>
  12. <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  13. </service>
  14. </services>
  15. <behaviors>
  16. <serviceBehaviors>
  17. <behavior name="WcfService3.Service1Behavior">
  18. <serviceMetadata httpGetEnabled="true"/>
  19. <serviceDebug includeExceptionDetailInFaults="false"/>
  20. </behavior>
  21. </serviceBehaviors>
  22. </behaviors>
  23. </system.serviceModel>
  24. </configuration>
  25.  
  26. namespace WcfService3
  27. {
  28. [ServiceContract]
  29. public interface IService1
  30. {
  31. [OperationContract]
  32. string GetData(string username, string password);
  33. }
  34.  
  35. [DataContract]
  36. public class Data
  37. {
  38. [DataMember]
  39. public string Username { get; set; }
  40.  
  41. [DataMember]
  42. public string Password { get; set; }
  43. }
  44. }
  45.  
  46. namespace WcfService3
  47. {
  48. public class Service1 : IService1
  49. {
  50. [WebInvoke(Method = "GET",
  51. RequestFormat = WebMessageFormat.Json,
  52. ResponseFormat = WebMessageFormat.Json,
  53. UriTemplate = "data/{user}/{pass}")]
  54. public string GetData(string user, string pass)
  55. {
  56. Data UserData = new Data()
  57. {
  58. Username = user,
  59. Password = pass
  60. };
  61.  
  62. MemoryStream stream = new MemoryStream();
  63. DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Data));
  64. ser.WriteObject(stream, UserData);
  65. string json = Encoding.Default.GetString(stream.ToArray());
  66. return json;
  67. }
  68. }
  69. }
  70.  
  71. <services>
  72. <service name="WcfService3.Service1" behaviorConfiguration="WcfService3.Service1Behavior">
  73. <!-- Service Endpoints -->
  74. <endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBehavior" contract="WcfService3.IService1">
  75. <identity>
  76. <dns value="localhost"/>
  77. </identity>
  78. </endpoint>
  79. <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  80. </service>
  81. </services>
  82.  
  83. <endpointBehaviors>
  84. <behavior name="webBehavior">
  85. <webHttp />
  86. </behavior>
  87. </endpointBehaviors>
  88.  
  89. namespace WcfService3
  90. {
  91. public class Service1 : IService1
  92. {
  93. [WebInvoke(Method = "GET",
  94. RequestFormat = WebMessageFormat.Json,
  95. ResponseFormat = WebMessageFormat.Json,
  96. UriTemplate = "data/{user}/{pass}")]
  97. public Data GetData(string user, string pass)
  98. {
  99. Data UserData = new Data()
  100. {
  101. Username = user,
  102. Password = pass
  103. };
  104.  
  105. return UserData;
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement