1 <%@ WebService Language="c#" Codebehind="ConverterService.asmx.cs" Class="WebServiceTests.ConverterService" %>
4 WARNING: This code was generated by a tool.
5 Changes to this file will be lost if the code is regenerated
9 using System.Collections;
11 using System.Xml.Serialization;
12 using System.Web.Services;
13 using System.Web.Services.Protocols;
14 using System.Web.Services.Description;
16 namespace WebServiceTests
18 public class UserInfo : SoapHeader
23 public class CurrencyInfo
25 public CurrencyInfo ()
29 public CurrencyInfo (string name, double rate)
44 [WebServiceAttribute (Namespace="urn:mono-ws-tests", Description="Web service that can make currency conversions")]
45 [SoapRpcServiceAttribute()]
46 public class ConverterService : System.Web.Services.WebService
48 static int userCount = 0;
49 static Hashtable conversionTable;
51 public UserInfo userInfo;
53 public SoapHeader unknown1;
54 public SoapHeader[] unknown2;
55 public SoapUnknownHeader unknown3;
56 public SoapUnknownHeader[] unknown4;
58 static ConverterService ()
60 conversionTable = new Hashtable ();
61 InternalSetCurrencyRate ("USD", 1);
62 InternalSetCurrencyRate ("EUR", 0.883884 );
63 InternalSetCurrencyRate ("GBP", 0.611817 );
64 InternalSetCurrencyRate ("JPY", 118.271 );
65 InternalSetCurrencyRate ("CAD", 1.36338 );
66 InternalSetCurrencyRate ("AUD", 1.51485 );
67 InternalSetCurrencyRate ("CHF", 1.36915 );
68 InternalSetCurrencyRate ("RUR", 30.4300 );
69 InternalSetCurrencyRate ("CNY", 8.27740 );
70 InternalSetCurrencyRate ("ZAR", 7.62645 );
71 InternalSetCurrencyRate ("MXN", 10.5025 );
74 [WebMethod (Description="Registers the user into the system")]
75 [SoapHeaderAttribute ("userInfo", Direction = SoapHeaderDirection.Out)]
76 public void Login (string a)
78 userInfo = new UserInfo ();
79 userInfo.userId = ++userCount;
82 [WebMethod (Description="Converts an amount from one currency to another currency")]
83 [SoapHeaderAttribute ("userInfo")]
84 public double Convert (string sourceCurrency, string targetCurrency, double value)
87 double usd = (1 / GetCurrencyRate (sourceCurrency)) * value;
88 return usd * GetCurrencyRate (targetCurrency);
91 [WebMethod (Description="Returns a list of currency rates")]
92 [SoapHeaderAttribute ("userInfo")]
93 public CurrencyInfo[] GetCurrencyInfo ()
97 lock (conversionTable)
99 CurrencyInfo[] info = new CurrencyInfo[conversionTable.Count];
101 foreach (CurrencyInfo cinfo in conversionTable.Values)
107 [WebMethod (Description="Sets the rate of a currency")]
108 [SoapHeaderAttribute ("userInfo")]
109 public void SetCurrencyRate (string currency, double rate)
112 InternalSetCurrencyRate (currency, rate);
115 static void InternalSetCurrencyRate (string currency, double rate)
117 lock (conversionTable)
119 conversionTable [currency] = new CurrencyInfo (currency, rate);
123 [WebMethod (Description="Returns the rate of a currency")]
124 [SoapHeaderAttribute ("userInfo")]
125 public double GetCurrencyRate ([XmlElement(DataType="Name")]string cname)
128 lock (conversionTable)
130 if (!conversionTable.ContainsKey (cname))
131 throw new SoapException ("Unknown currency '" + cname + "'", SoapException.ServerFaultCode);
133 return ((CurrencyInfo) conversionTable [cname]).Rate;
138 public void Test (Simple dada1, int dada)
143 [WebMethod (MessageName="Test2")]
144 public void Test (int[] dada2, byte[] dada3, int dada)
150 public System.Collections.Specialized.StringCollection TestArrays (string[] info, string lang)
157 if (userInfo == null)
158 throw new SoapException ("User not logged", SoapException.ServerFaultCode);
162 [return: SoapElement("retret")]
163 public MyInfo GetTestInfo (string s, out string d)
169 [SoapHeaderAttribute ("unknown1")]
171 public void TestUnknownHeader1 ()
173 if (unknown1 == null)
174 throw new Exception ("Header is null");
176 if (unknown1.Actor != "hi")
177 throw new Exception ("Invalid actor");
180 [SoapHeaderAttribute ("unknown2")]
182 public void TestUnknownHeader2 ()
184 if (unknown2 == null || unknown2.Length != 1)
185 throw new Exception ("Header is null");
187 if (unknown2[0].Actor != "hi")
188 throw new Exception ("Invalid actor");
191 [SoapHeaderAttribute ("unknown3")]
193 public int TestUnknownHeader3 ()
195 if (unknown3 == null)
196 throw new Exception ("Header is null");
198 if (unknown3.Actor != "hi")
199 throw new Exception ("Invalid actor");
201 XmlElement child = unknown3.Element ["userId"];
202 return int.Parse (child.InnerText);
205 [SoapHeaderAttribute ("unknown4")]
207 public int TestUnknownHeader4 ()
209 if (unknown4 == null || unknown4.Length != 1)
210 throw new Exception ("Header is null");
212 if (unknown4[0].Actor != "hi")
213 throw new Exception ("Invalid actor");
215 XmlElement child = unknown4[0].Element ["userId"];
216 return int.Parse (child.InnerText);
223 public string b = "hi";