ConvDocEncWra.asmx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <%@ WebService Language="c#" Codebehind="ConverterService.asmx.cs" Class="WebServiceTests.ConverterService" %>
  2. /*
  3. WARNING: This code was generated by a tool.
  4. Changes to this file will be lost if the code is regenerated
  5. */
  6. using System;
  7. using System.Collections;
  8. using System.Xml;
  9. using System.Xml.Serialization;
  10. using System.Web.Services;
  11. using System.Web.Services.Protocols;
  12. using System.Web.Services.Description;
  13. namespace WebServiceTests
  14. {
  15. public class UserInfo : SoapHeader
  16. {
  17. public int userId;
  18. }
  19. public class CurrencyInfo
  20. {
  21. public CurrencyInfo ()
  22. {
  23. }
  24. public CurrencyInfo (string name, double rate)
  25. {
  26. Name = name;
  27. Rate = rate;
  28. }
  29. public string Name;
  30. public double Rate;
  31. }
  32. public class Simple
  33. {
  34. public int Dada;
  35. }
  36. [WebServiceAttribute (Namespace="urn:mono-ws-tests", Description="Web service that can make currency conversions")]
  37. [SoapDocumentServiceAttribute (Use=SoapBindingUse.Encoded, ParameterStyle=SoapParameterStyle.Wrapped)]
  38. public class ConverterService : System.Web.Services.WebService
  39. {
  40. static int userCount = 0;
  41. static Hashtable conversionTable;
  42. public UserInfo userInfo;
  43. public SoapHeader unknown1;
  44. public SoapHeader[] unknown2;
  45. public SoapUnknownHeader unknown3;
  46. public SoapUnknownHeader[] unknown4;
  47. static ConverterService ()
  48. {
  49. conversionTable = new Hashtable ();
  50. InternalSetCurrencyRate ("USD", 1);
  51. InternalSetCurrencyRate ("EUR", 0.883884 );
  52. InternalSetCurrencyRate ("GBP", 0.611817 );
  53. InternalSetCurrencyRate ("JPY", 118.271 );
  54. InternalSetCurrencyRate ("CAD", 1.36338 );
  55. InternalSetCurrencyRate ("AUD", 1.51485 );
  56. InternalSetCurrencyRate ("CHF", 1.36915 );
  57. InternalSetCurrencyRate ("RUR", 30.4300 );
  58. InternalSetCurrencyRate ("CNY", 8.27740 );
  59. InternalSetCurrencyRate ("ZAR", 7.62645 );
  60. InternalSetCurrencyRate ("MXN", 10.5025 );
  61. }
  62. [WebMethod (Description="Registers the user into the system")]
  63. [SoapHeaderAttribute ("userInfo", Direction = SoapHeaderDirection.Out)]
  64. public void Login (string a)
  65. {
  66. userInfo = new UserInfo ();
  67. userInfo.userId = ++userCount;
  68. }
  69. [WebMethod (Description="Converts an amount from one currency to another currency")]
  70. [SoapHeaderAttribute ("userInfo")]
  71. public double Convert (string sourceCurrency, string targetCurrency, double value)
  72. {
  73. CheckUser ();
  74. double usd = (1 / GetCurrencyRate (sourceCurrency)) * value;
  75. return usd * GetCurrencyRate (targetCurrency);
  76. }
  77. [WebMethod (Description="Returns a list of currency rates")]
  78. [SoapHeaderAttribute ("userInfo")]
  79. public CurrencyInfo[] GetCurrencyInfo ()
  80. {
  81. CheckUser ();
  82. lock (conversionTable)
  83. {
  84. CurrencyInfo[] info = new CurrencyInfo[conversionTable.Count];
  85. int n = 0;
  86. foreach (CurrencyInfo cinfo in conversionTable.Values)
  87. info [n++] = cinfo;
  88. return info;
  89. }
  90. }
  91. [WebMethod (Description="Sets the rate of a currency")]
  92. [SoapHeaderAttribute ("userInfo")]
  93. public void SetCurrencyRate (string currency, double rate)
  94. {
  95. CheckUser ();
  96. InternalSetCurrencyRate (currency, rate);
  97. }
  98. static void InternalSetCurrencyRate (string currency, double rate)
  99. {
  100. lock (conversionTable)
  101. {
  102. conversionTable [currency] = new CurrencyInfo (currency, rate);
  103. }
  104. }
  105. [WebMethod (Description="Returns the rate of a currency")]
  106. [SoapHeaderAttribute ("userInfo")]
  107. public double GetCurrencyRate ([XmlElement(DataType="Name")]string cname)
  108. {
  109. CheckUser ();
  110. lock (conversionTable)
  111. {
  112. if (!conversionTable.ContainsKey (cname))
  113. throw new SoapException ("Unknown currency '" + cname + "'", SoapException.ServerFaultCode);
  114. return ((CurrencyInfo) conversionTable [cname]).Rate;
  115. }
  116. }
  117. [WebMethod]
  118. public void Test (Simple dada1, int dada)
  119. {
  120. dada = 1;
  121. }
  122. [WebMethod (MessageName="Test2")]
  123. public void Test (int[] dada2, byte[] dada3, int dada)
  124. {
  125. dada = 1;
  126. }
  127. [WebMethod]
  128. public System.Collections.Specialized.StringCollection TestArrays (string[] info, string lang)
  129. {
  130. return null;
  131. }
  132. void CheckUser ()
  133. {
  134. if (userInfo == null)
  135. throw new SoapException ("User not logged", SoapException.ServerFaultCode);
  136. }
  137. [WebMethod]
  138. [return: SoapElement("retret")]
  139. public MyInfo GetTestInfo (string s, out string d)
  140. {
  141. d = "iii";
  142. return new MyInfo();
  143. }
  144. [SoapHeaderAttribute ("unknown1")]
  145. [WebMethod]
  146. public void TestUnknownHeader1 ()
  147. {
  148. if (unknown1 == null)
  149. throw new Exception ("Header is null");
  150. if (unknown1.Actor != "hi")
  151. throw new Exception ("Invalid actor");
  152. }
  153. [SoapHeaderAttribute ("unknown2")]
  154. [WebMethod]
  155. public void TestUnknownHeader2 ()
  156. {
  157. if (unknown2 == null || unknown2.Length != 1)
  158. throw new Exception ("Header is null");
  159. if (unknown2[0].Actor != "hi")
  160. throw new Exception ("Invalid actor");
  161. }
  162. [SoapHeaderAttribute ("unknown3")]
  163. [WebMethod]
  164. public int TestUnknownHeader3 ()
  165. {
  166. if (unknown3 == null)
  167. throw new Exception ("Header is null");
  168. if (unknown3.Actor != "hi")
  169. throw new Exception ("Invalid actor");
  170. XmlElement child = unknown3.Element ["userId"];
  171. return int.Parse (child.InnerText);
  172. }
  173. [SoapHeaderAttribute ("unknown4")]
  174. [WebMethod]
  175. public int TestUnknownHeader4 ()
  176. {
  177. if (unknown4 == null || unknown4.Length != 1)
  178. throw new Exception ("Header is null");
  179. if (unknown4[0].Actor != "hi")
  180. throw new Exception ("Invalid actor");
  181. XmlElement child = unknown4[0].Element ["userId"];
  182. return int.Parse (child.InnerText);
  183. }
  184. }
  185. public class MyInfo
  186. {
  187. public int a = 4;
  188. public string b = "hi";
  189. }
  190. }