* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web.Services / Test / standalone / server / ConvDocLitBar.asmx
1 <%@ WebService Language="c#" Codebehind="ConverterService.asmx.cs" Class="WebServiceTests.ConverterService" %>
2
3 /*
4 WARNING: This code was generated by a tool.
5 Changes to this file will be lost if the code is regenerated
6 */
7
8 using System;
9 using System.Collections;
10 using System.Xml;
11 using System.Xml.Serialization;
12 using System.Web.Services;
13 using System.Web.Services.Protocols;
14 using System.Web.Services.Description;
15
16 namespace WebServiceTests
17 {
18         public class UserInfo : SoapHeader 
19         {
20                 public int userId;
21         }
22         
23         public class CurrencyInfo
24         {
25                 public CurrencyInfo ()
26                 {
27                 }
28
29                 public CurrencyInfo (string name, double rate) 
30                 {
31                         Name = name;
32                         Rate = rate;
33                 }
34                 
35                 public string Name;
36                 public double Rate;
37         }
38         
39         public class Simple
40         {
41                 public int Dada;
42         }
43
44         [WebServiceAttribute (Namespace="urn:mono-ws-tests", Description="Web service that can make currency conversions")]
45         [SoapDocumentServiceAttribute (Use=SoapBindingUse.Literal, ParameterStyle=SoapParameterStyle.Bare)]
46         public class ConverterService : System.Web.Services.WebService
47         {
48                 static int userCount = 0;
49                 static Hashtable conversionTable;
50                 
51                 public UserInfo userInfo;
52                 
53                 public SoapHeader unknown1;
54                 public SoapHeader[] unknown2;
55                 public SoapUnknownHeader unknown3;
56                 public SoapUnknownHeader[] unknown4;
57
58                 static ConverterService ()
59                 {
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 );
72                 }
73                 
74                 [WebMethod (Description="Registers the user into the system")]
75                 [SoapHeaderAttribute ("userInfo", Direction = SoapHeaderDirection.Out)]
76                 public void Login (string a)
77                 {
78                         userInfo = new UserInfo ();
79                         userInfo.userId = ++userCount;
80                 }
81
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)
85                 {
86                         CheckUser ();
87                         double usd = (1 / GetCurrencyRate (sourceCurrency)) * value;
88                         return usd * GetCurrencyRate (targetCurrency);
89                 }
90                 
91                 [WebMethod (Description="Returns a list of currency rates")]
92                 [SoapHeaderAttribute ("userInfo")]
93                 public CurrencyInfo[] GetCurrencyInfo ()
94                 {
95                         CheckUser ();
96                         
97                         lock (conversionTable)
98                         {
99                                 CurrencyInfo[] info = new CurrencyInfo[conversionTable.Count];
100                                 int n = 0;
101                                 foreach (CurrencyInfo cinfo in conversionTable.Values)
102                                         info [n++] = cinfo;
103                                 return info;
104                         }
105                 }
106                 
107                 [WebMethod (Description="Sets the rate of a currency")]
108                 [SoapHeaderAttribute ("userInfo")]
109                 public void SetCurrencyRate (string currency, double rate)
110                 {
111                         CheckUser ();
112                         InternalSetCurrencyRate (currency, rate);
113                 }
114
115                 static void InternalSetCurrencyRate (string currency, double rate)
116                 {
117                         lock (conversionTable)
118                         {
119                                 conversionTable [currency] = new CurrencyInfo (currency, rate);
120                         }
121                 }
122
123                 [WebMethod (Description="Returns the rate of a currency")]
124                 [SoapHeaderAttribute ("userInfo")]
125                 public double GetCurrencyRate ([XmlElement(DataType="Name")]string cname)
126                 {
127                         CheckUser ();
128                         lock (conversionTable)
129                         {
130                                 if (!conversionTable.ContainsKey (cname))
131                                         throw new SoapException ("Unknown currency '" + cname + "'", SoapException.ServerFaultCode);
132                                         
133                                 return ((CurrencyInfo) conversionTable [cname]).Rate;
134                         }
135                 }
136                 
137                 [WebMethod]
138                 public void Test (Simple dada1, int dada)
139                 {
140                         dada = 1;
141                 }
142                 
143                 [WebMethod (MessageName="Test2")]
144                 public void Test (int[] dada2, byte[] dada3, int dada)
145                 {
146                         dada = 1;
147                 }
148                 
149                 [WebMethod]
150                 public System.Collections.Specialized.StringCollection TestArrays (string[] info, string lang)
151                 {
152                         return null;
153                 }
154                 
155                 void CheckUser ()
156                 {
157                         if (userInfo == null) 
158                                 throw new SoapException ("User not logged", SoapException.ServerFaultCode);
159                 }
160                 
161                 [WebMethod]
162                 [return: XmlElement("retret")]
163                 public MyInfo GetTestInfo (string s, out string d)
164                 {
165                         d = "iii";
166                         return new MyInfo();
167                 }
168                 
169                 [SoapHeaderAttribute ("unknown1")]
170                 [WebMethod]
171                 public void TestUnknownHeader1 ()
172                 {
173                         if (unknown1 == null)
174                                 throw new Exception ("Header is null");
175
176                         if (unknown1.Actor != "hi")
177                                 throw new Exception ("Invalid actor");
178                 }
179                 
180                 [SoapHeaderAttribute ("unknown2")]
181                 [WebMethod]
182                 public void TestUnknownHeader2 ()
183                 {
184                         if (unknown2 == null || unknown2.Length != 1)
185                                 throw new Exception ("Header is null");
186
187                         if (unknown2[0].Actor != "hi")
188                                 throw new Exception ("Invalid actor");
189                 }
190                 
191                 [SoapHeaderAttribute ("unknown3")]
192                 [WebMethod]
193                 public int TestUnknownHeader3 ()
194                 {
195                         if (unknown3 == null)
196                                 throw new Exception ("Header is null");
197
198                         if (unknown3.Actor != "hi")
199                                 throw new Exception ("Invalid actor");
200                                 
201                         XmlElement child = unknown3.Element ["userId"];
202                         return int.Parse (child.InnerText);
203                 }
204                 
205                 [SoapHeaderAttribute ("unknown4")]
206                 [WebMethod]
207                 public int TestUnknownHeader4 ()
208                 {
209                         if (unknown4 == null || unknown4.Length != 1)
210                                 throw new Exception ("Header is null");
211
212                         if (unknown4[0].Actor != "hi")
213                                 throw new Exception ("Invalid actor");
214                                 
215                         XmlElement child = unknown4[0].Element ["userId"];
216                         return int.Parse (child.InnerText);
217                 }
218         }
219
220         public class MyInfo
221         {
222                 public int a = 4;
223                 public string b = "hi";
224         }
225 }