ServiceDescriptionReflectorTest.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. //
  2. // ServiceDescriptionReflectorTest.cs
  3. //
  4. // Author:
  5. // Gert Driesen <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc.
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.Globalization;
  12. using System.IO;
  13. using System.Web.Services;
  14. using System.Web.Services.Description;
  15. using System.Xml.Serialization;
  16. namespace MonoTests.System.Web.Services.Description
  17. {
  18. [TestFixture]
  19. public class ServiceDescriptionReflectorTest
  20. {
  21. [Test]
  22. [Category ("NotWorking")]
  23. public void IncludeTest ()
  24. {
  25. ServiceDescriptionReflector reflector = new ServiceDescriptionReflector ();
  26. reflector.Reflect (typeof (IncludeTestServices), "http://localhost/IncludeTestServices.asmx");
  27. Assert.AreEqual (0, reflector.Schemas.Count, "#1");
  28. Assert.AreEqual (1, reflector.ServiceDescriptions.Count, "#2");
  29. ServiceDescription sd = reflector.ServiceDescriptions[0];
  30. Assert.IsNull (sd.Name, "#3");
  31. Assert.AreEqual (1, sd.Types.Schemas.Count, "#4");
  32. StringWriter sw = new StringWriter ();
  33. sd.Write (sw);
  34. Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
  35. "<?xml version=\"1.0\" encoding=\"utf-16\"?>{0}" +
  36. #if NET_2_0
  37. "<wsdl:definitions xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:tm=\"http://microsoft.com/wsdl/mime/textMatching/\"" +
  38. " xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\"" +
  39. " xmlns:tns=\"http://tempuri.org/\" xmlns:s=\"http://www.w3.org/2001/XMLSchema\"" +
  40. " xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\"" +
  41. " xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" targetNamespace=\"http://tempuri.org/\"" +
  42. " xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">{0}" +
  43. #else
  44. "<wsdl:definitions xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"" +
  45. " xmlns:s=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"" +
  46. " xmlns:tns=\"http://tempuri.org/\" xmlns:tm=\"http://microsoft.com/wsdl/mime/textMatching/\"" +
  47. " xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" targetNamespace=\"http://tempuri.org/\"" +
  48. " xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\">{0}" +
  49. #endif
  50. " <wsdl:types>{0}" +
  51. " <s:schema elementFormDefault=\"qualified\" targetNamespace=\"http://tempuri.org/\">{0}" +
  52. " <s:element name=\"EchoString\">{0}" +
  53. " <s:complexType>{0}" +
  54. " <s:sequence>{0}" +
  55. " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"strval\" type=\"s:string\" />{0}" +
  56. " </s:sequence>{0}" +
  57. " </s:complexType>{0}" +
  58. " </s:element>{0}" +
  59. " <s:element name=\"EchoStringResponse\">{0}" +
  60. " <s:complexType>{0}" +
  61. " <s:sequence>{0}" +
  62. " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"MyTime\" type=\"s:time\" />{0}" +
  63. " </s:sequence>{0}" +
  64. " </s:complexType>{0}" +
  65. " </s:element>{0}" +
  66. " <s:element name=\"Vehicle\">{0}" +
  67. " <s:complexType>{0}" +
  68. " <s:sequence>{0}" +
  69. " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"licenseNumber\" type=\"s:string\" />{0}" +
  70. " </s:sequence>{0}" +
  71. " </s:complexType>{0}" +
  72. " </s:element>{0}" +
  73. " <s:element name=\"VehicleResponse\">{0}" +
  74. " <s:complexType>{0}" +
  75. " <s:sequence>{0}" +
  76. " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"NewVehicle\" nillable=\"true\" type=\"tns:Vehicle\" />{0}" +
  77. " </s:sequence>{0}" +
  78. " </s:complexType>{0}" +
  79. " </s:element>{0}" +
  80. " <s:complexType name=\"Vehicle\" abstract=\"true\">{0}" +
  81. " <s:sequence>{0}" +
  82. " <s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"licenseNumber\" type=\"s:string\" />{0}" +
  83. " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"make\" type=\"s:dateTime\" />{0}" +
  84. " <s:element minOccurs=\"1\" maxOccurs=\"1\" name=\"age\" type=\"tns:TimeSpan\" />{0}" +
  85. " </s:sequence>{0}" +
  86. " </s:complexType>{0}" +
  87. " <s:complexType name=\"TimeSpan\" />{0}" +
  88. " <s:complexType name=\"Car\">{0}" +
  89. " <s:complexContent mixed=\"false\">{0}" +
  90. " <s:extension base=\"tns:Vehicle\" />{0}" +
  91. " </s:complexContent>{0}" +
  92. " </s:complexType>{0}" +
  93. " </s:schema>{0}" +
  94. " </wsdl:types>{0}" +
  95. " <wsdl:message name=\"EchoStringSoapIn\">{0}" +
  96. " <wsdl:part name=\"parameters\" element=\"tns:EchoString\" />{0}" +
  97. " </wsdl:message>{0}" +
  98. " <wsdl:message name=\"EchoStringSoapOut\">{0}" +
  99. " <wsdl:part name=\"parameters\" element=\"tns:EchoStringResponse\" />{0}" +
  100. " </wsdl:message>{0}" +
  101. " <wsdl:message name=\"VehicleSoapIn\">{0}" +
  102. " <wsdl:part name=\"parameters\" element=\"tns:Vehicle\" />{0}" +
  103. " </wsdl:message>{0}" +
  104. " <wsdl:message name=\"VehicleSoapOut\">{0}" +
  105. " <wsdl:part name=\"parameters\" element=\"tns:VehicleResponse\" />{0}" +
  106. " </wsdl:message>{0}" +
  107. " <wsdl:portType name=\"IncludeTestServicesSoap\">{0}" +
  108. " <wsdl:operation name=\"EchoString\">{0}" +
  109. " <wsdl:input message=\"tns:EchoStringSoapIn\" />{0}" +
  110. " <wsdl:output message=\"tns:EchoStringSoapOut\" />{0}" +
  111. " </wsdl:operation>{0}" +
  112. " <wsdl:operation name=\"Vehicle\">{0}" +
  113. " <wsdl:input message=\"tns:VehicleSoapIn\" />{0}" +
  114. " <wsdl:output message=\"tns:VehicleSoapOut\" />{0}" +
  115. " </wsdl:operation>{0}" +
  116. " </wsdl:portType>{0}" +
  117. " <wsdl:binding name=\"IncludeTestServicesSoap\" type=\"tns:IncludeTestServicesSoap\">{0}" +
  118. #if NET_2_0
  119. " <soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" />{0}" +
  120. #else
  121. " <soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" style=\"document\" />{0}" +
  122. #endif
  123. " <wsdl:operation name=\"EchoString\">{0}" +
  124. " <soap:operation soapAction=\"http://tempuri.org/EchoString\" style=\"document\" />{0}" +
  125. " <wsdl:input>{0}" +
  126. " <soap:body use=\"literal\" />{0}" +
  127. " </wsdl:input>{0}" +
  128. " <wsdl:output>{0}" +
  129. " <soap:body use=\"literal\" />{0}" +
  130. " </wsdl:output>{0}" +
  131. " </wsdl:operation>{0}" +
  132. " <wsdl:operation name=\"Vehicle\">{0}" +
  133. " <soap:operation soapAction=\"http://tempuri.org/Vehicle\" style=\"document\" />{0}" +
  134. " <wsdl:input>{0}" +
  135. " <soap:body use=\"literal\" />{0}" +
  136. " </wsdl:input>{0}" +
  137. " <wsdl:output>{0}" +
  138. " <soap:body use=\"literal\" />{0}" +
  139. " </wsdl:output>{0}" +
  140. " </wsdl:operation>{0}" +
  141. " </wsdl:binding>{0}" +
  142. #if NET_2_0
  143. " <wsdl:binding name=\"IncludeTestServicesSoap12\" type=\"tns:IncludeTestServicesSoap\">{0}" +
  144. " <soap12:binding transport=\"http://schemas.xmlsoap.org/soap/http\" />{0}" +
  145. " <wsdl:operation name=\"EchoString\">{0}" +
  146. " <soap12:operation soapAction=\"http://tempuri.org/EchoString\" style=\"document\" />{0}" +
  147. " <wsdl:input>{0}" +
  148. " <soap12:body use=\"literal\" />{0}" +
  149. " </wsdl:input>{0}" +
  150. " <wsdl:output>{0}" +
  151. " <soap12:body use=\"literal\" />{0}" +
  152. " </wsdl:output>{0}" +
  153. " </wsdl:operation>{0}" +
  154. " <wsdl:operation name=\"Vehicle\">{0}" +
  155. " <soap12:operation soapAction=\"http://tempuri.org/Vehicle\" style=\"document\" />{0}" +
  156. " <wsdl:input>{0}" +
  157. " <soap12:body use=\"literal\" />{0}" +
  158. " </wsdl:input>{0}" +
  159. " <wsdl:output>{0}" +
  160. " <soap12:body use=\"literal\" />{0}" +
  161. " </wsdl:output>{0}" +
  162. " </wsdl:operation>{0}" +
  163. " </wsdl:binding>{0}" +
  164. #endif
  165. " <wsdl:service name=\"IncludeTestServices\">{0}" +
  166. #if ONLY_1_1
  167. " <documentation xmlns=\"http://schemas.xmlsoap.org/wsdl/\" />{0}" +
  168. #endif
  169. " <wsdl:port name=\"IncludeTestServicesSoap\" binding=\"tns:IncludeTestServicesSoap\">{0}" +
  170. " <soap:address location=\"http://localhost/IncludeTestServices.asmx\" />{0}" +
  171. " </wsdl:port>{0}" +
  172. #if NET_2_0
  173. " <wsdl:port name=\"IncludeTestServicesSoap12\" binding=\"tns:IncludeTestServicesSoap12\">{0}" +
  174. " <soap12:address location=\"http://localhost/IncludeTestServices.asmx\" />{0}" +
  175. " </wsdl:port>{0}" +
  176. #endif
  177. " </wsdl:service>{0}" +
  178. "</wsdl:definitions>", Environment.NewLine), sw.ToString (), "#5");
  179. }
  180. public class IncludeTestServices : WebService
  181. {
  182. [WebMethod ()]
  183. [return: XmlElement ("MyTime", DataType = "time")]
  184. public DateTime EchoString ([XmlElement (DataType = "string")] string strval)
  185. {
  186. return DateTime.Now;
  187. }
  188. [WebMethod ()]
  189. [XmlInclude (typeof (Car))]
  190. public Vehicle Vehicle (string licenseNumber)
  191. {
  192. if (licenseNumber == "0") {
  193. Vehicle v = new Car ();
  194. v.licenseNumber = licenseNumber;
  195. return v;
  196. } else {
  197. return null;
  198. }
  199. }
  200. }
  201. [XmlRoot ("NewVehicle")]
  202. public abstract class Vehicle
  203. {
  204. public string licenseNumber;
  205. public DateTime make;
  206. public TimeSpan age;
  207. }
  208. public class Car : Vehicle
  209. {
  210. }
  211. }
  212. }