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.
12 using NUnit.Framework;
15 using System.Globalization;
17 using System.Web.Services;
18 using System.Web.Services.Description;
19 using System.Xml.Schema;
20 using System.Xml.Serialization;
22 namespace MonoTests.System.Web.Services.Description
25 public class ServiceDescriptionReflectorTest
29 public void ReflectNullableInt ()
31 ServiceDescriptionReflector r =
32 new ServiceDescriptionReflector ();
33 r.Reflect (typeof (NullableContainer), null);
34 ServiceDescription sd = r.ServiceDescriptions [0];
35 XmlSchema xs = sd.Types.Schemas [0];
36 XmlSchemaElement el = null;
37 foreach (XmlSchemaElement e in xs.Items) {
38 if (e.Name != "GetNullResponse")
43 XmlSchemaComplexType ct =
44 el.SchemaType as XmlSchemaComplexType;
45 XmlSchemaSequence s = ct.Particle as XmlSchemaSequence;
46 XmlSchemaElement e2 = s.Items [0] as XmlSchemaElement;
47 Assert.IsTrue (e2.IsNillable);
51 [Category ("NotWorking")]
52 public void IncludeTest ()
54 ServiceDescriptionReflector reflector = new ServiceDescriptionReflector ();
55 reflector.Reflect (typeof (IncludeTestServices), "http://localhost/IncludeTestServices.asmx");
57 Assert.AreEqual (0, reflector.Schemas.Count, "#1");
58 Assert.AreEqual (1, reflector.ServiceDescriptions.Count, "#2");
60 ServiceDescription sd = reflector.ServiceDescriptions[0];
62 Assert.IsNull (sd.Name, "#3");
63 Assert.AreEqual (1, sd.Types.Schemas.Count, "#4");
65 StringWriter sw = new StringWriter ();
68 Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
69 "<?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 "<wsdl:definitions xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"" +
79 " xmlns:s=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"" +
80 " xmlns:tns=\"http://tempuri.org/\" xmlns:tm=\"http://microsoft.com/wsdl/mime/textMatching/\"" +
81 " xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" targetNamespace=\"http://tempuri.org/\"" +
82 " xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">{0}" +
85 " <s:schema elementFormDefault=\"qualified\" targetNamespace=\"http://tempuri.org/\">{0}" +
86 " <s:element name=\"EchoString\">{0}" +
87 " <s:complexType>{0}" +
89 " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"strval\" type=\"s:string\" />{0}" +
91 " </s:complexType>{0}" +
93 " <s:element name=\"EchoStringResponse\">{0}" +
94 " <s:complexType>{0}" +
96 " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"MyTime\" type=\"s:time\" />{0}" +
98 " </s:complexType>{0}" +
100 " <s:element name=\"Vehicle\">{0}" +
101 " <s:complexType>{0}" +
103 " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"licenseNumber\" type=\"s:string\" />{0}" +
104 " </s:sequence>{0}" +
105 " </s:complexType>{0}" +
107 " <s:element name=\"VehicleResponse\">{0}" +
108 " <s:complexType>{0}" +
110 " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"NewVehicle\" nillable=\"true\" type=\"tns:Vehicle\" />{0}" +
111 " </s:sequence>{0}" +
112 " </s:complexType>{0}" +
114 " <s:complexType name=\"Vehicle\" abstract=\"true\">{0}" +
116 " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"licenseNumber\" type=\"s:string\" />{0}" +
117 " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"make\" type=\"s:dateTime\" />{0}" +
118 " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"age\" type=\"tns:TimeSpan\" />{0}" +
119 " </s:sequence>{0}" +
120 " </s:complexType>{0}" +
121 " <s:complexType name=\"TimeSpan\" />{0}" +
122 " <s:complexType name=\"Car\">{0}" +
123 " <s:complexContent mixed=\"false\">{0}" +
124 " <s:extension base=\"tns:Vehicle\" />{0}" +
125 " </s:complexContent>{0}" +
126 " </s:complexType>{0}" +
128 " </wsdl:types>{0}" +
129 " <wsdl:message name=\"EchoStringSoapIn\">{0}" +
130 " <wsdl:part name=\"parameters\" element=\"tns:EchoString\" />{0}" +
131 " </wsdl:message>{0}" +
132 " <wsdl:message name=\"EchoStringSoapOut\">{0}" +
133 " <wsdl:part name=\"parameters\" element=\"tns:EchoStringResponse\" />{0}" +
134 " </wsdl:message>{0}" +
135 " <wsdl:message name=\"VehicleSoapIn\">{0}" +
136 " <wsdl:part name=\"parameters\" element=\"tns:Vehicle\" />{0}" +
137 " </wsdl:message>{0}" +
138 " <wsdl:message name=\"VehicleSoapOut\">{0}" +
139 " <wsdl:part name=\"parameters\" element=\"tns:VehicleResponse\" />{0}" +
140 " </wsdl:message>{0}" +
141 " <wsdl:portType name=\"IncludeTestServicesSoap\">{0}" +
142 " <wsdl:operation name=\"EchoString\">{0}" +
143 " <wsdl:input message=\"tns:EchoStringSoapIn\" />{0}" +
144 " <wsdl:output message=\"tns:EchoStringSoapOut\" />{0}" +
145 " </wsdl:operation>{0}" +
146 " <wsdl:operation name=\"Vehicle\">{0}" +
147 " <wsdl:input message=\"tns:VehicleSoapIn\" />{0}" +
148 " <wsdl:output message=\"tns:VehicleSoapOut\" />{0}" +
149 " </wsdl:operation>{0}" +
150 " </wsdl:portType>{0}" +
151 " <wsdl:binding name=\"IncludeTestServicesSoap\" type=\"tns:IncludeTestServicesSoap\">{0}" +
153 " <soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" />{0}" +
155 " <soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" style=\"document\" />{0}" +
157 " <wsdl:operation name=\"EchoString\">{0}" +
158 " <soap:operation soapAction=\"http://tempuri.org/EchoString\" style=\"document\" />{0}" +
160 " <soap:body use=\"literal\" />{0}" +
161 " </wsdl:input>{0}" +
162 " <wsdl:output>{0}" +
163 " <soap:body use=\"literal\" />{0}" +
164 " </wsdl:output>{0}" +
165 " </wsdl:operation>{0}" +
166 " <wsdl:operation name=\"Vehicle\">{0}" +
167 " <soap:operation soapAction=\"http://tempuri.org/Vehicle\" style=\"document\" />{0}" +
169 " <soap:body use=\"literal\" />{0}" +
170 " </wsdl:input>{0}" +
171 " <wsdl:output>{0}" +
172 " <soap:body use=\"literal\" />{0}" +
173 " </wsdl:output>{0}" +
174 " </wsdl:operation>{0}" +
175 " </wsdl:binding>{0}" +
177 " <wsdl:binding name=\"IncludeTestServicesSoap12\" type=\"tns:IncludeTestServicesSoap\">{0}" +
178 " <soap12:binding transport=\"http://schemas.xmlsoap.org/soap/http\" />{0}" +
179 " <wsdl:operation name=\"EchoString\">{0}" +
180 " <soap12:operation soapAction=\"http://tempuri.org/EchoString\" style=\"document\" />{0}" +
182 " <soap12:body use=\"literal\" />{0}" +
183 " </wsdl:input>{0}" +
184 " <wsdl:output>{0}" +
185 " <soap12:body use=\"literal\" />{0}" +
186 " </wsdl:output>{0}" +
187 " </wsdl:operation>{0}" +
188 " <wsdl:operation name=\"Vehicle\">{0}" +
189 " <soap12:operation soapAction=\"http://tempuri.org/Vehicle\" style=\"document\" />{0}" +
191 " <soap12:body use=\"literal\" />{0}" +
192 " </wsdl:input>{0}" +
193 " <wsdl:output>{0}" +
194 " <soap12:body use=\"literal\" />{0}" +
195 " </wsdl:output>{0}" +
196 " </wsdl:operation>{0}" +
197 " </wsdl:binding>{0}" +
199 " <wsdl:service name=\"IncludeTestServices\">{0}" +
201 " <documentation xmlns=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
203 " <wsdl:port name=\"IncludeTestServicesSoap\" binding=\"tns:IncludeTestServicesSoap\">{0}" +
204 " <soap:address location=\"http://localhost/IncludeTestServices.asmx\" />{0}" +
207 " <wsdl:port name=\"IncludeTestServicesSoap12\" binding=\"tns:IncludeTestServicesSoap12\">{0}" +
208 " <soap12:address location=\"http://localhost/IncludeTestServices.asmx\" />{0}" +
211 " </wsdl:service>{0}" +
212 "</wsdl:definitions>", Environment.NewLine), sw.ToString (), "#5");
215 public class IncludeTestServices : WebService
218 [return: XmlElement ("MyTime", DataType = "time")]
219 public DateTime EchoString ([XmlElement (DataType = "string")] string strval)
225 [XmlInclude (typeof (Car))]
226 public Vehicle Vehicle (string licenseNumber)
228 if (licenseNumber == "0") {
229 Vehicle v = new Car ();
230 v.licenseNumber = licenseNumber;
237 [XmlRoot ("NewVehicle")]
238 public abstract class Vehicle
240 public string licenseNumber;
241 public DateTime make;
245 public class Car : Vehicle
250 public class NullableContainer
252 [WebMethod (Description="Test nullables")]
253 public int? GetNull ()