2 // ServiceDescriptionReflectorTest.cs
5 // Gert Driesen <drieseng@users.sourceforge.net>
6 // Atsushi Enomoto <atsushi@ximian.com>
8 // Copyright (C) 2007 Gert Driesen
9 // Copyright (C) 2006 Novell, Inc.
14 using NUnit.Framework;
17 using System.Globalization;
19 using System.Web.Services;
20 using System.Web.Services.Description;
21 using System.Web.Services.Protocols;
22 using System.Xml.Schema;
23 using System.Xml.Serialization;
25 namespace MonoTests.System.Web.Services.Description
28 public class ServiceDescriptionReflectorTest
31 public void ReflectNullableInt ()
33 ServiceDescriptionReflector r =
34 new ServiceDescriptionReflector ();
35 r.Reflect (typeof (NullableContainer), null);
36 ServiceDescription sd = r.ServiceDescriptions [0];
37 XmlSchema xs = sd.Types.Schemas [0];
38 XmlSchemaElement el = null;
39 foreach (XmlSchemaElement e in xs.Items) {
40 if (e.Name != "GetNullResponse")
45 XmlSchemaComplexType ct =
46 el.SchemaType as XmlSchemaComplexType;
47 XmlSchemaSequence s = ct.Particle as XmlSchemaSequence;
48 XmlSchemaElement e2 = s.Items [0] as XmlSchemaElement;
49 Assert.IsTrue (e2.IsNillable);
52 [Category ("NotWorking")]
53 public void IncludeTest ()
55 ServiceDescriptionReflector reflector = new ServiceDescriptionReflector ();
56 reflector.Reflect (typeof (IncludeTestServices), "http://localhost/IncludeTestServices.asmx");
58 Assert.AreEqual (0, reflector.Schemas.Count, "#1");
59 Assert.AreEqual (1, reflector.ServiceDescriptions.Count, "#2");
61 ServiceDescription sd = reflector.ServiceDescriptions[0];
63 Assert.IsNull (sd.Name, "#3");
64 Assert.AreEqual (1, sd.Types.Schemas.Count, "#4");
66 StringWriter sw = new StringWriter ();
69 Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
70 "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
71 "<wsdl:definitions xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tm=\"http://microsoft.com/wsdl/mime/textMatching/\"" +
72 " xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\"" +
73 " xmlns:tns=\"http://tempuri.org/\" xmlns:s=\"http://www.w3.org/2001/XMLSchema\"" +
74 " xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\"" +
75 " xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" targetNamespace=\"http://tempuri.org/\"" +
76 " xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">{0}" +
78 " <s:schema elementFormDefault=\"qualified\" targetNamespace=\"http://tempuri.org/\">{0}" +
79 " <s:element name=\"EchoString\">{0}" +
80 " <s:complexType>{0}" +
82 " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"strval\" type=\"s:string\" />{0}" +
84 " </s:complexType>{0}" +
86 " <s:element name=\"EchoStringResponse\">{0}" +
87 " <s:complexType>{0}" +
89 " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"MyTime\" type=\"s:time\" />{0}" +
91 " </s:complexType>{0}" +
93 " <s:element name=\"Vehicle\">{0}" +
94 " <s:complexType>{0}" +
96 " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"licenseNumber\" type=\"s:string\" />{0}" +
98 " </s:complexType>{0}" +
100 " <s:element name=\"VehicleResponse\">{0}" +
101 " <s:complexType>{0}" +
103 " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"NewVehicle\" nillable=\"true\" type=\"tns:Vehicle\" />{0}" +
104 " </s:sequence>{0}" +
105 " </s:complexType>{0}" +
107 " <s:complexType name=\"Vehicle\" abstract=\"true\">{0}" +
109 " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"licenseNumber\" type=\"s:string\" />{0}" +
110 " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"make\" type=\"s:dateTime\" />{0}" +
111 " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"age\" type=\"tns:TimeSpan\" />{0}" +
112 " </s:sequence>{0}" +
113 " </s:complexType>{0}" +
114 " <s:complexType name=\"TimeSpan\" />{0}" +
115 " <s:complexType name=\"Car\">{0}" +
116 " <s:complexContent mixed=\"false\">{0}" +
117 " <s:extension base=\"tns:Vehicle\" />{0}" +
118 " </s:complexContent>{0}" +
119 " </s:complexType>{0}" +
121 " </wsdl:types>{0}" +
122 " <wsdl:message name=\"EchoStringSoapIn\">{0}" +
123 " <wsdl:part name=\"parameters\" element=\"tns:EchoString\" />{0}" +
124 " </wsdl:message>{0}" +
125 " <wsdl:message name=\"EchoStringSoapOut\">{0}" +
126 " <wsdl:part name=\"parameters\" element=\"tns:EchoStringResponse\" />{0}" +
127 " </wsdl:message>{0}" +
128 " <wsdl:message name=\"VehicleSoapIn\">{0}" +
129 " <wsdl:part name=\"parameters\" element=\"tns:Vehicle\" />{0}" +
130 " </wsdl:message>{0}" +
131 " <wsdl:message name=\"VehicleSoapOut\">{0}" +
132 " <wsdl:part name=\"parameters\" element=\"tns:VehicleResponse\" />{0}" +
133 " </wsdl:message>{0}" +
134 " <wsdl:portType name=\"IncludeTestServicesSoap\">{0}" +
135 " <wsdl:operation name=\"EchoString\">{0}" +
136 " <wsdl:input message=\"tns:EchoStringSoapIn\" />{0}" +
137 " <wsdl:output message=\"tns:EchoStringSoapOut\" />{0}" +
138 " </wsdl:operation>{0}" +
139 " <wsdl:operation name=\"Vehicle\">{0}" +
140 " <wsdl:input message=\"tns:VehicleSoapIn\" />{0}" +
141 " <wsdl:output message=\"tns:VehicleSoapOut\" />{0}" +
142 " </wsdl:operation>{0}" +
143 " </wsdl:portType>{0}" +
144 " <wsdl:binding name=\"IncludeTestServicesSoap\" type=\"tns:IncludeTestServicesSoap\">{0}" +
145 " <soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" />{0}" +
146 " <wsdl:operation name=\"EchoString\">{0}" +
147 " <soap:operation soapAction=\"http://tempuri.org/EchoString\" style=\"document\" />{0}" +
149 " <soap:body use=\"literal\" />{0}" +
150 " </wsdl:input>{0}" +
151 " <wsdl:output>{0}" +
152 " <soap:body use=\"literal\" />{0}" +
153 " </wsdl:output>{0}" +
154 " </wsdl:operation>{0}" +
155 " <wsdl:operation name=\"Vehicle\">{0}" +
156 " <soap:operation soapAction=\"http://tempuri.org/Vehicle\" style=\"document\" />{0}" +
158 " <soap:body use=\"literal\" />{0}" +
159 " </wsdl:input>{0}" +
160 " <wsdl:output>{0}" +
161 " <soap:body use=\"literal\" />{0}" +
162 " </wsdl:output>{0}" +
163 " </wsdl:operation>{0}" +
164 " </wsdl:binding>{0}" +
165 " <wsdl:binding name=\"IncludeTestServicesSoap12\" type=\"tns:IncludeTestServicesSoap\">{0}" +
166 " <soap12:binding transport=\"http://schemas.xmlsoap.org/soap/http\" />{0}" +
167 " <wsdl:operation name=\"EchoString\">{0}" +
168 " <soap12:operation soapAction=\"http://tempuri.org/EchoString\" style=\"document\" />{0}" +
170 " <soap12:body use=\"literal\" />{0}" +
171 " </wsdl:input>{0}" +
172 " <wsdl:output>{0}" +
173 " <soap12:body use=\"literal\" />{0}" +
174 " </wsdl:output>{0}" +
175 " </wsdl:operation>{0}" +
176 " <wsdl:operation name=\"Vehicle\">{0}" +
177 " <soap12:operation soapAction=\"http://tempuri.org/Vehicle\" style=\"document\" />{0}" +
179 " <soap12:body use=\"literal\" />{0}" +
180 " </wsdl:input>{0}" +
181 " <wsdl:output>{0}" +
182 " <soap12:body use=\"literal\" />{0}" +
183 " </wsdl:output>{0}" +
184 " </wsdl:operation>{0}" +
185 " </wsdl:binding>{0}" +
186 " <wsdl:service name=\"IncludeTestServices\">{0}" +
187 " <wsdl:port name=\"IncludeTestServicesSoap\" binding=\"tns:IncludeTestServicesSoap\">{0}" +
188 " <soap:address location=\"http://localhost/IncludeTestServices.asmx\" />{0}" +
190 " <wsdl:port name=\"IncludeTestServicesSoap12\" binding=\"tns:IncludeTestServicesSoap12\">{0}" +
191 " <soap12:address location=\"http://localhost/IncludeTestServices.asmx\" />{0}" +
193 " </wsdl:service>{0}" +
194 "</wsdl:definitions>", Environment.NewLine), sw.ToString (), "#5");
198 [Category ("NotWorking")]
199 public void ReflectTypeNonDefaultBinding ()
202 ServiceDescriptionReflector r =
203 new ServiceDescriptionReflector ();
204 r.Reflect (typeof (EdaInterface), "urn:foo");
205 //foreach (ServiceDescription sss in r.ServiceDescriptions) sss.Write (Console.Out);
206 // It should create two wsdls, one for www.DefaultNamespace.org and
207 // another for urn:localBinding:local .
208 Assert.AreEqual (2, r.ServiceDescriptions.Count, "#1");
209 Assert.IsNotNull (r.ServiceDescriptions ["www.DefaultNamespace.org"], "#1-1");
210 ServiceDescription sd = r.ServiceDescriptions ["urn:localBinding:local"];
211 Assert.IsNotNull (sd, "#1-2");
213 Assert.AreEqual (2, sd.Bindings.Count, "#2-2.0");
214 Binding b = sd.Bindings [0];
215 Assert.AreEqual ("Local", b.Name, "#3");
219 public void Bug79087 ()
221 ServiceDescriptionReflector r =
222 new ServiceDescriptionReflector ();
223 r.Reflect (typeof (Bug79807Service), "urn:foo");
224 StringWriter sw = new StringWriter ();
225 r.ServiceDescriptions [0].Write (sw);
226 ServiceDescription.Read (new StringReader (sw.ToString ()));
230 public void EmptyAction ()
232 ServiceDescriptionReflector r =
233 new ServiceDescriptionReflector ();
234 r.Reflect (typeof (EmptyActionService), "urn:foo");
235 Binding b = r.ServiceDescriptions [0].Bindings ["EmptyActionServiceSoap"];
236 OperationBinding o = b.Operations [0];
237 SoapOperationBinding sob = o.Extensions [0] as SoapOperationBinding;
238 Assert.AreEqual (String.Empty, sob.SoapAction);
242 public void Bug332150 ()
244 ServiceDescriptionReflector r =
245 new ServiceDescriptionReflector ();
246 r.Reflect (typeof (Bug332150Service), "urn:foo");
247 StringWriter sw = new StringWriter ();
248 r.ServiceDescriptions [0].Write (sw);
249 ServiceDescription.Read (new StringReader (sw.ToString ()));
253 public void Bug345448 ()
255 ServiceDescriptionReflector r =
256 new ServiceDescriptionReflector ();
257 r.Reflect (typeof (Bug345448Service), "urn:foo");
259 ServiceDescription sd = r.ServiceDescriptions [0];
261 Assert.AreEqual("Bug345448ServiceSoap", sd.Bindings [0].Name, "sd #1");
262 Assert.AreEqual("Bug345448ServiceSoap12", sd.Bindings [1].Name, "sd #2");
266 public void Bug345449 ()
268 ServiceDescriptionReflector r =
269 new ServiceDescriptionReflector ();
270 r.Reflect (typeof (Bug345448Service), "urn:foo");
271 ServiceDescription sd = r.ServiceDescriptions [0];
273 Assert.AreEqual("Bug345448ServiceSoap", sd.Services [0].Ports [0].Name, "sd #3");
274 Assert.AreEqual("Bug345448ServiceSoap12", sd.Services [0].Ports [1].Name, "sd #4");
278 public void Bug360241 ()
280 // Make sure the map for service client is properly created
281 new Bug360241SoapHttpClientProtocol ();
284 public class IncludeTestServices : WebService
287 [return: XmlElement ("MyTime", DataType = "time")]
288 public DateTime EchoString ([XmlElement (DataType = "string")] string strval)
294 [XmlInclude (typeof (Car))]
295 public Vehicle Vehicle (string licenseNumber)
297 if (licenseNumber == "0") {
298 Vehicle v = new Car ();
299 v.licenseNumber = licenseNumber;
306 [XmlRoot ("NewVehicle")]
307 public abstract class Vehicle
309 public string licenseNumber;
310 public DateTime make;
314 public class Car : Vehicle
318 public class NullableContainer
320 [WebMethod (Description="Test nullables")]
321 public int? GetNull ()
328 [WebServiceAttribute (Namespace = "www.DefaultNamespace.org")]
329 [WebServiceBindingAttribute (Name = "Local", Namespace = "urn:localBinding:local")]
330 public class EdaInterface : WebService
343 [SoapDocumentMethodAttribute ("urn:localBinding:local:LocalBindingMethod",
344 RequestNamespace = "urn:localBinding:local",
346 Use = SoapBindingUse.Literal,
347 ParameterStyle = SoapParameterStyle.Bare)]
348 public void BindingMethod ()
354 public class Bug79807Item
356 public string stringOne;
357 public string stringTwo;
360 public class Bug79807AnotherItem
362 public string stringOne;
363 public string stringTwo;
368 public class Bug79807Service : WebService
371 public Bug79807Item [] Method1 (int count)
373 Bug79807Item [] arr = new Bug79807Item [count];
374 for (int i = 0;i < count;i++) {
375 arr [i].stringOne = "one";
376 arr [i].stringTwo = "two";
382 public Bug79807AnotherItem [] Method2 (int count)
384 Bug79807AnotherItem [] arr = new Bug79807AnotherItem [count];
385 for (int i = 0;i < count;i++) {
386 arr [i].stringOne = "one";
387 arr [i].stringTwo = "two";
393 [WebService (Namespace = "http://tempuri.org/")]
394 public class EmptyActionService : WebService
397 [SoapDocumentMethod ("")]
398 public string HelloWorld () {
399 return "Hello World";
403 [WebService (Namespace = "http://tempuri.org/")]
404 [WebServiceBinding (ConformsTo = WsiProfiles.BasicProfile1_1)]
405 public abstract class Bug332150SecureWebService : WebService
407 public Bug332150SecureWebService ()
412 public bool Login (string userName, string password)
418 [WebService (Namespace = "http://tempuri.org/")]
419 [WebServiceBinding (ConformsTo = WsiProfiles.BasicProfile1_1)]
420 public class Bug332150Service : Bug332150SecureWebService
422 public Bug332150Service ()
427 public string HelloWorld ()
429 return "Hello World";
433 [WebService (Namespace = "http://tempuri.org/")]
434 [WebServiceBindingAttribute (Name = "AnotherBinding", Namespace = "http://tempuri.org/")]
435 public class Bug345448Service : WebService
438 //[SoapDocumentMethodAttribute (Binding="AnotherBinding")]
439 public string HelloWorld ()
441 return "Hello World";
445 [WebServiceBindingAttribute (Name = "AnotherBinding", Namespace = "http://tempuri.org/")]
446 public class Bug360241SoapHttpClientProtocol : SoapHttpClientProtocol