WsdlExporterTest.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. //
  2. // WsdlExporterTest.cs
  3. //
  4. // Author:
  5. // Ankit Jain <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Text;
  31. using System.ServiceModel.Channels;
  32. using System.ServiceModel.Description;
  33. using NUnit.Framework;
  34. using System.Runtime.Serialization;
  35. using System.ServiceModel;
  36. using System.Web.Services;
  37. using WSServiceDescription = System.Web.Services.Description.ServiceDescription;
  38. using WSMessage = System.Web.Services.Description.Message;
  39. using WSBinding = System.Web.Services.Description.Binding;
  40. using QName = System.Xml.XmlQualifiedName;
  41. using SMMessage = System.ServiceModel.Channels.Message;
  42. using System.Xml;
  43. using System.Web.Services.Description;
  44. using System.Xml.Schema;
  45. using System.Xml.Serialization;
  46. using System.Reflection;
  47. namespace MonoTests.System.ServiceModel.Description
  48. {
  49. [TestFixture]
  50. public class WsdlExporterTest
  51. {
  52. [Test]
  53. [Category ("NotWorking")]
  54. public void Ctor1 ()
  55. {
  56. WsdlExporter we = new WsdlExporter ();
  57. Assert.IsNotNull (we.GetGeneratedMetadata ());
  58. Assert.IsNotNull (we.GeneratedWsdlDocuments, "#c1");
  59. Assert.AreEqual (0, we.GeneratedWsdlDocuments.Count, "#c2");
  60. Assert.IsNotNull (we.GeneratedXmlSchemas, "#c3");
  61. Assert.AreEqual (0, we.GeneratedXmlSchemas.Count, "#c4");
  62. }
  63. [Test]
  64. public void ExportEndpointTest ()
  65. {
  66. WsdlExporter we = new WsdlExporter ();
  67. ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
  68. se.Binding = new BasicHttpBinding ();
  69. se.Address = new EndpointAddress ("http://localhost:8080");
  70. //TEST Invalid name: 5se.Name = "Service#1";
  71. //se.Name = "Service0";
  72. //se.ListenUri = new Uri ("http://localhost:8080/svc");
  73. we.ExportEndpoint (se);
  74. MetadataSet ms = we.GetGeneratedMetadata ();
  75. Assert.AreEqual (6, ms.MetadataSections.Count);
  76. CheckContract_IEchoService (ms, "#eet01");
  77. WSServiceDescription sd = GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest");
  78. CheckServicePort (GetService (sd, "service", "ExportEndpointTest"),
  79. "BasicHttpBinding_IEchoService", new XmlQualifiedName ("BasicHttpBinding_IEchoService", "http://tempuri.org/"),
  80. "http://localhost:8080/", "#eet02");
  81. CheckBasicHttpBinding (sd, "BasicHttpBinding_IEchoService", new XmlQualifiedName ("IEchoService", "http://myns/echo"),
  82. "Echo", "http://myns/echo/IEchoService/Echo", true, true, "#eet03");
  83. }
  84. [Test]
  85. public void ExportEndpointTest2 ()
  86. {
  87. WsdlExporter we = new WsdlExporter ();
  88. ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService2)));
  89. se.Binding = new BasicHttpBinding ();
  90. se.Address = new EndpointAddress ("http://localhost:8080");
  91. we.ExportEndpoint (se);
  92. MetadataSet ms = we.GetGeneratedMetadata ();
  93. Assert.AreEqual (5, ms.MetadataSections.Count);
  94. WSServiceDescription sd = ms.MetadataSections [0].Metadata as WSServiceDescription;
  95. CheckContract_IEchoService2 (ms, "#eet20");
  96. CheckServicePort (GetService (GetServiceDescription (ms, "http://tempuri.org/", "#eet21"), "service", "ExportEndpointTest"),
  97. "BasicHttpBinding_ThisIsEchoService", new XmlQualifiedName ("BasicHttpBinding_ThisIsEchoService", "http://tempuri.org/"),
  98. "http://localhost:8080/", "#eet22");
  99. CheckBasicHttpBinding (sd, "BasicHttpBinding_ThisIsEchoService",
  100. new XmlQualifiedName ("ThisIsEchoService", "http://tempuri.org/"),
  101. "Echo", "http://tempuri.org/ThisIsEchoService/Echo", true, true, "#eet03");
  102. //FIXME: CheckXmlSchema
  103. }
  104. [Test]
  105. public void ExportEndpointTest3 ()
  106. {
  107. WsdlExporter we = new WsdlExporter ();
  108. /*ContractDescription contract =*/ ContractDescription.GetContract (typeof (IEchoService2));
  109. ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService2)));
  110. se.Binding = new BasicHttpBinding ();
  111. se.Address = new EndpointAddress ("http://localhost:8080");
  112. we.ExportEndpoint (se);
  113. se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
  114. se.Binding = new BasicHttpBinding ();
  115. se.Address = new EndpointAddress ("http://somehost");
  116. we.ExportEndpoint (se);
  117. MetadataSet ms = we.GetGeneratedMetadata ();
  118. Assert.AreEqual (7, ms.MetadataSections.Count);
  119. Service svc = GetService (
  120. GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest"),
  121. "service", "ExportEndpointTest");
  122. CheckContract_IEchoService (ms, "#eet31");
  123. CheckServicePort (svc, "BasicHttpBinding_IEchoService",
  124. new XmlQualifiedName ("BasicHttpBinding_IEchoService", "http://tempuri.org/"),
  125. "http://somehost/", "#eet32");
  126. CheckContract_IEchoService2 (ms, "#eet33");
  127. CheckServicePort (svc, "BasicHttpBinding_ThisIsEchoService",
  128. new XmlQualifiedName ("BasicHttpBinding_ThisIsEchoService", "http://tempuri.org/"),
  129. "http://localhost:8080/", "#eet34");
  130. WSServiceDescription sd = ms.MetadataSections [0].Metadata as WSServiceDescription;
  131. CheckBasicHttpBinding (sd, "BasicHttpBinding_IEchoService", new XmlQualifiedName ("IEchoService", "http://myns/echo"),
  132. "Echo", "http://myns/echo/IEchoService/Echo", true, true, "#eet35");
  133. CheckBasicHttpBinding (sd, "BasicHttpBinding_ThisIsEchoService", new XmlQualifiedName ("ThisIsEchoService", "http://tempuri.org/"),
  134. "Echo", "http://tempuri.org/ThisIsEchoService/Echo", true, true, "#eet36");
  135. //FIXME: CheckXmlSchema
  136. }
  137. [Test]
  138. public void ExportContractInvalid1 ()
  139. {
  140. WsdlExporter we = new WsdlExporter ();
  141. we.ExportContract (ContractDescription.GetContract (typeof (IEchoService2)));
  142. //Duplicate contract QNames not allowed
  143. ExportContractExpectException (we, ContractDescription.GetContract (typeof (IEchoService2)),
  144. typeof (ArgumentException), "ExportContractInvalid1");
  145. }
  146. [Test]
  147. public void ExportContractInvalid2 ()
  148. {
  149. WsdlExporter we = new WsdlExporter ();
  150. we.ExportContract (ContractDescription.GetContract (typeof (IEchoService2)));
  151. //Invalid as IEchoService3.Echo is http://tempuri.org/Echo message which has already been exported
  152. //Even though, the service name is different
  153. ExportContractExpectException (we, ContractDescription.GetContract (typeof (IEchoService3)),
  154. typeof (InvalidOperationException), "ExportContractInvalid2");
  155. }
  156. [Test]
  157. public void ExportContract1 ()
  158. {
  159. WsdlExporter we = new WsdlExporter ();
  160. we.ExportContract (ContractDescription.GetContract (typeof (IEchoService)));
  161. MetadataSet ms = we.GetGeneratedMetadata ();
  162. Assert.AreEqual (5, ms.MetadataSections.Count);
  163. CheckContract_IEchoService (ms, "ExportContract1");
  164. }
  165. [Test]
  166. public void ExportContract2 ()
  167. {
  168. WsdlExporter we = new WsdlExporter ();
  169. we.ExportContract (ContractDescription.GetContract (typeof (IFoo1)));
  170. MetadataSet ms = we.GetGeneratedMetadata ();
  171. Assert.AreEqual (5, ms.MetadataSections.Count);
  172. }
  173. [Test]
  174. public void ExportContract2a ()
  175. {
  176. WsdlExporter we = new WsdlExporter ();
  177. we.ExportContract (ContractDescription.GetContract (typeof (IFoo1)));
  178. //IFoo1a.Op1 is the same operations as IFoo1.Op1, so cant be exported
  179. //the message element for both is the same
  180. //(Compared by names not signature)
  181. ExportContractExpectException (we, ContractDescription.GetContract (typeof (IFoo1a)),
  182. typeof (InvalidOperationException), "ExportContract2a");
  183. }
  184. [Test]
  185. [Category ("NotWorking")]
  186. public void ExportMessageContract ()
  187. {
  188. WsdlExporter we = new WsdlExporter ();
  189. ContractDescription cd = ContractDescription.GetContract (typeof (IFoo2));
  190. we.ExportContract (cd);
  191. }
  192. [Test]
  193. [Category ("NotWorking")]
  194. //FIXME: One check not working, BeginGetResult
  195. public void ExportMexContract ()
  196. {
  197. WsdlExporter we = new WsdlExporter ();
  198. ContractDescription cd = ContractDescription.GetContract (typeof (IMetadataExchange));
  199. we.ExportContract (cd);
  200. MetadataSet ms = we.GetGeneratedMetadata ();
  201. WSServiceDescription sd = GetServiceDescription (ms, "http://schemas.microsoft.com/2006/04/mex", "ExportMexContract");
  202. CheckMessage (sd, "IMetadataExchange_Get_InputMessage", "request", "http://schemas.microsoft.com/Message:MessageBody", true, "#exc0");
  203. CheckMessage (sd, "IMetadataExchange_Get_OutputMessage", "GetResult", "http://schemas.microsoft.com/Message:MessageBody", true, "#exc1");
  204. //PortType
  205. PortType port_type = sd.PortTypes ["IMetadataExchange"];
  206. Assert.IsNotNull (port_type, "#exc2, PortType named IMetadataExchange not found.");
  207. Assert.AreEqual (1, port_type.Operations.Count, "#exc3");
  208. Operation op = port_type.Operations [0];
  209. Assert.AreEqual ("Get", op.Name, "#exc4");
  210. Assert.AreEqual (2, op.Messages.Count, "#exc5");
  211. CheckOperationMessage (op.Messages [0], "http://schemas.microsoft.com/2006/04/mex:IMetadataExchange_Get_InputMessage",
  212. typeof (OperationInput), "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get");
  213. CheckOperationMessage (op.Messages [1], "http://schemas.microsoft.com/2006/04/mex:IMetadataExchange_Get_OutputMessage",
  214. typeof (OperationOutput), "http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse");
  215. CheckSpecialMessage (ms, "#exc6");
  216. Assert.AreEqual (1, we.GeneratedWsdlDocuments.Count, "GeneratedWsdlDocuments.Count");
  217. Assert.AreEqual (1, we.GeneratedXmlSchemas.Count, "GeneratedXmlSchemas.Count");
  218. }
  219. [Test]
  220. //Currently throws InvalidDataContractException on mono, but once the code is
  221. //moved to a IWsdlExportExtension, InvalidOperationException will get throw
  222. [Category ("NotWorking")]
  223. [Ignore ("fails under .NET; I never bothered to fix the test")]
  224. public void ExportBar1Contract ()
  225. {
  226. WsdlExporter we = new WsdlExporter ();
  227. ContractDescription cd = ContractDescription.GetContract (typeof (Bar1));
  228. //Cannot export as operation Foo has >1 param so Message param gets treated
  229. //as any other param, but it is not serializable!
  230. ExportContractExpectException (we, cd, typeof (InvalidOperationException), "ExportBar1Contract");
  231. }
  232. //Helper methods
  233. //Checks the ComplexType emitted for CLR type Message
  234. void CheckSpecialMessage (MetadataSet ms, string label)
  235. {
  236. //Check ComplexType MessageBody
  237. XmlSchema xs = GetXmlSchema (ms, "http://schemas.microsoft.com/Message", label + " #csm0");
  238. foreach (XmlSchemaObject o in xs.SchemaTypes.Values) {
  239. XmlSchemaComplexType complex_type = o as XmlSchemaComplexType;
  240. if (complex_type == null)
  241. continue;
  242. if (complex_type.Name != "MessageBody")
  243. continue;
  244. //MessageBody
  245. Assert.IsNotNull (complex_type.Particle, label + " #cms1");
  246. Assert.AreEqual (typeof (XmlSchemaSequence), complex_type.Particle.GetType (), label + " #cms2");
  247. XmlSchemaSequence seq = (XmlSchemaSequence) complex_type.Particle;
  248. Assert.AreEqual (1, seq.Items.Count, label + " #cms3");
  249. Assert.AreEqual (typeof (XmlSchemaAny), seq.Items [0].GetType (), label + " #cms4");
  250. XmlSchemaAny any = (XmlSchemaAny) seq.Items [0];
  251. Assert.AreEqual ("##any", any.Namespace, label + " #cms5");
  252. Assert.AreEqual (0, any.MinOccurs, label + " #cms6");
  253. Assert.AreEqual ("unbounded", any.MaxOccursString, label + " #cms6");
  254. }
  255. }
  256. //somebody fix this name!
  257. void ExportContractExpectException (WsdlExporter we, ContractDescription cd, Type exception_type, string msg)
  258. {
  259. try {
  260. we.ExportContract (cd);
  261. } catch (Exception e) {
  262. if (e.GetType () == exception_type)
  263. return;
  264. Assert.Fail (String.Format ("[{0}] Expected {1}, but got : {2}", msg, exception_type, e));
  265. }
  266. Assert.Fail (String.Format ("[{0}] Expected {1}", msg, exception_type));
  267. }
  268. WSServiceDescription GetServiceDescription (MetadataSet ms, string ns, string msg)
  269. {
  270. foreach (MetadataSection section in ms.MetadataSections) {
  271. WSServiceDescription sd = section.Metadata as WSServiceDescription;
  272. if (sd == null)
  273. continue;
  274. if (sd.TargetNamespace == ns) {
  275. /*Assert.AreEqual ("http://schemas.xmlsoap.org/wsdl/", section.Dialect, msg + " Dialect");
  276. Assert.AreEqual (id, section.Identifier, msg + "Identifier");
  277. Assert.AreEqual (0, section.Attributes.Count, "#cw4");*/
  278. return sd;
  279. }
  280. }
  281. Assert.Fail (String.Format ("[{0}] ServiceDescription for ns : {1} not found.", msg, ns));
  282. return null;
  283. }
  284. XmlSchema GetXmlSchema (MetadataSet ms, string ns, string msg)
  285. {
  286. foreach (MetadataSection section in ms.MetadataSections) {
  287. XmlSchema xs = section.Metadata as XmlSchema;
  288. if (xs == null)
  289. continue;
  290. if (xs.TargetNamespace == ns) {
  291. /*Assert.AreEqual ("http://schemas.xmlsoap.org/wxsl/", section.Dialect, msg + " Dialect");
  292. Assert.AreEqual (id, section.Identifier, msg + "Identifier");
  293. Assert.AreEqual (0, section.Attributes.Count, "#cw4");*/
  294. return xs;
  295. }
  296. }
  297. Assert.Fail (String.Format ("[{0}] XmlSchema for tns : {1} not found.", msg, ns));
  298. return null;
  299. }
  300. Service GetService (WSServiceDescription sd, string name, string label)
  301. {
  302. Service ret = sd.Services [name];
  303. if (ret == null)
  304. Assert.Fail (String.Format ("[{0}] Service named '{1}' not found.", label, name));
  305. return ret;
  306. }
  307. WSBinding GetBinding (WSServiceDescription sd, string name, string label)
  308. {
  309. WSBinding ret = sd.Bindings [name];
  310. if (ret == null)
  311. Assert.Fail (String.Format ("[{0}] Binding named '{1}' not found.", label, name));
  312. return ret;
  313. }
  314. OperationBinding GetOperationBinding (WSBinding b, string name, string label)
  315. {
  316. foreach (OperationBinding op in b.Operations)
  317. if (op.Name == name)
  318. return op;
  319. Assert.Fail (String.Format ("[{0}] OperationBinding named '{1}' not found.", label, name));
  320. return null;
  321. }
  322. void CheckBasicHttpBinding (WSServiceDescription wsd, string binding_name, XmlQualifiedName binding_type,
  323. string operation_name, string action, bool has_input, bool has_output, string label)
  324. {
  325. WSBinding b = GetBinding (wsd, binding_name, label);
  326. OperationBinding op = GetOperationBinding (b, operation_name, label + " CheckBasicHttpBinding");
  327. Assert.AreEqual (binding_type, b.Type, label + " #cbh0");
  328. if (has_input) {
  329. InputBinding inb = op.Input;
  330. Assert.IsNotNull (inb, label + " #cbh1");
  331. Assert.AreEqual (1, inb.Extensions.Count, label + " #cbh2");
  332. Assert.AreEqual (typeof (SoapBodyBinding), inb.Extensions [0].GetType (), label + " #cbh3");
  333. SoapBodyBinding soap_binding = (SoapBodyBinding) inb.Extensions [0];
  334. Assert.AreEqual (SoapBindingUse.Literal, soap_binding.Use, label + " #cbh4");
  335. if (action != null) {
  336. Assert.AreEqual (1, op.Extensions.Count, label + " #chb5");
  337. Assert.AreEqual (typeof (SoapOperationBinding), op.Extensions [0].GetType (), label + " #cbh6");
  338. SoapOperationBinding sopb = (SoapOperationBinding) op.Extensions [0];
  339. Assert.AreEqual (action, sopb.SoapAction, label + " #cbh7");
  340. }
  341. }
  342. if (has_output) {
  343. OutputBinding outb = op.Output;
  344. Assert.IsNotNull (outb, label + " #cbh10");
  345. Assert.AreEqual (1, outb.Extensions.Count, label + " #cbh11");
  346. Assert.AreEqual (typeof (SoapBodyBinding), outb.Extensions [0].GetType (), label + " #cbh12");
  347. SoapBodyBinding soap_binding = (SoapBodyBinding) outb.Extensions [0];
  348. Assert.AreEqual (SoapBindingUse.Literal, soap_binding.Use, label + " #cbh13");
  349. }
  350. Assert.AreEqual (1, b.Extensions.Count, label + " #cbh20");
  351. Assert.AreEqual (typeof (SoapBinding), b.Extensions [0].GetType (), label + " #cbh21");
  352. SoapBinding sb = (SoapBinding) b.Extensions [0];
  353. Assert.AreEqual (SoapBinding.HttpTransport, sb.Transport, label + " #cbh22");
  354. }
  355. void CheckServicePort (Service svc, string port_name, XmlQualifiedName binding_name, string address, string label)
  356. {
  357. Port port = svc.Ports [port_name];
  358. Assert.IsNotNull (port, label + " #csp0");
  359. Assert.AreEqual (port.Binding, binding_name, label + " #csp1");
  360. Assert.AreEqual (1, port.Extensions.Count, label + " #csp2");
  361. Assert.AreEqual (typeof (SoapAddressBinding), port.Extensions [0].GetType (), label + " #csp3");
  362. SoapAddressBinding sab = (SoapAddressBinding) port.Extensions [0];
  363. Assert.AreEqual (address, sab.Location, label + " #csp3");
  364. }
  365. void CheckContract_IEchoService2 (MetadataSet ms, string label)
  366. {
  367. WSServiceDescription wsd = GetServiceDescription (ms, "http://tempuri.org/", label + "#a1");
  368. Assert.AreEqual (3, wsd.Messages.Count, "#cw5");
  369. Assert.IsNotNull (wsd.Messages [0]);
  370. // WSMessage m = wsd.Messages [0];
  371. CheckMessage (wsd, "ThisIsEchoService_Echo_InputMessage", "http://tempuri.org/:Echo");
  372. CheckMessage (wsd, "ThisIsEchoService_Echo_OutputMessage", "http://tempuri.org/:EchoResponse");
  373. CheckMessage (wsd, "ThisIsEchoService_DoubleIt_InputMessage", "http://tempuri.org/:DoubleIt");
  374. //PortTypes
  375. Assert.AreEqual (1, wsd.PortTypes.Count, "#cw6");
  376. PortType port = wsd.PortTypes [0];
  377. Assert.AreEqual ("ThisIsEchoService", port.Name, "#cw7");
  378. //Operations
  379. Assert.AreEqual (2, port.Operations.Count, "#cw8");
  380. //Operations [0]
  381. Operation op = port.Operations [0];
  382. Assert.AreEqual ("Echo", op.Name, "#co1");
  383. Assert.AreEqual (0, op.Extensions.Count, "#co2");
  384. Assert.IsNull (op.ParameterOrder, "#co3");
  385. Assert.AreEqual ("", op.ParameterOrderString, "#co4");
  386. Assert.AreEqual (0, op.Faults.Count, "#co5");
  387. //OperationMessages
  388. Assert.AreEqual (2, op.Messages.Count, "#co6");
  389. Assert.AreEqual (OperationFlow.RequestResponse, op.Messages.Flow, "#co7");
  390. CheckOperationMessage (op.Messages [0], "http://tempuri.org/:ThisIsEchoService_Echo_InputMessage",
  391. typeof (OperationInput), "http://tempuri.org/ThisIsEchoService/Echo");
  392. CheckOperationMessage (op.Messages [1], "http://tempuri.org/:ThisIsEchoService_Echo_OutputMessage",
  393. typeof (OperationOutput), "http://tempuri.org/ThisIsEchoService/EchoResponse");
  394. op = port.Operations [1];
  395. Assert.AreEqual ("DoubleIt", op.Name, "#co8");
  396. Assert.AreEqual (0, op.Extensions.Count, "#co9");
  397. Assert.IsNull (op.ParameterOrder, "#co10");
  398. Assert.AreEqual ("", op.ParameterOrderString, "#co11");
  399. Assert.AreEqual (0, op.Faults.Count, "#co12");
  400. //OperationMessages
  401. Assert.AreEqual (1, op.Messages.Count, "#co13");
  402. Assert.AreEqual (OperationFlow.OneWay, op.Messages.Flow, "#co14");
  403. CheckOperationMessage (op.Messages [0], "http://tempuri.org/:ThisIsEchoService_DoubleIt_InputMessage",
  404. typeof (OperationInput), "http://tempuri.org/ThisIsEchoService/DoubleIt");
  405. /* FIXME: Assert.AreEqual (1, wsd.Types.Schemas.Count, "#co20");
  406. XmlSchema xs = wsd.Types.Schemas [0];
  407. Assert.AreEqual (4, xs.Includes.Count);
  408. //FIXME: Check the imports.. */
  409. }
  410. void CheckContract_IEchoService (MetadataSet ms, string label)
  411. {
  412. WSServiceDescription wsd = GetServiceDescription (ms, "http://myns/echo", label + "#a0");
  413. Assert.AreEqual (4, wsd.Messages.Count, "#cw5");
  414. Assert.IsNotNull (wsd.Messages [0]);
  415. //WSMessage m = wsd.Messages [0];
  416. CheckMessage (wsd, "IEchoService_Echo_InputMessage", "http://myns/echo:Echo");
  417. CheckMessage (wsd, "IEchoService_Echo_OutputMessage", "http://myns/echo:EchoResponse");
  418. CheckMessage (wsd, "IEchoService_DoubleIt_InputMessage", "http://myns/echo:DoubleIt");
  419. CheckMessage (wsd, "IEchoService_DoubleIt_OutputMessage", "http://myns/echo:DoubleItResponse");
  420. //PortTypes
  421. Assert.AreEqual (1, wsd.PortTypes.Count, "#cw6");
  422. PortType port = wsd.PortTypes [0];
  423. Assert.AreEqual ("IEchoService", port.Name, "#cw7");
  424. //Operations
  425. Assert.AreEqual (2, port.Operations.Count, "#cw8");
  426. //Operations [0]
  427. Operation op = port.Operations [0];
  428. Assert.AreEqual ("Echo", op.Name, "#co1");
  429. Assert.AreEqual (0, op.Extensions.Count, "#co2");
  430. Assert.IsNull (op.ParameterOrder, "#co3");
  431. Assert.AreEqual ("", op.ParameterOrderString, "#co4");
  432. Assert.AreEqual (0, op.Faults.Count, "#co5");
  433. //OperationMessages
  434. Assert.AreEqual (2, op.Messages.Count, "#co6");
  435. Assert.AreEqual (OperationFlow.RequestResponse, op.Messages.Flow, "#co7");
  436. CheckOperationMessage (op.Messages [0], "http://myns/echo:IEchoService_Echo_InputMessage", typeof (OperationInput), "http://myns/echo/IEchoService/Echo");
  437. CheckOperationMessage (op.Messages [1], "http://myns/echo:IEchoService_Echo_OutputMessage", typeof (OperationOutput), "http://myns/echo/IEchoService/EchoResponse");
  438. op = port.Operations [1];
  439. Assert.AreEqual ("DoubleIt", op.Name, "#co8");
  440. Assert.AreEqual (0, op.Extensions.Count, "#co9");
  441. Assert.IsNull (op.ParameterOrder, "#co10");
  442. Assert.AreEqual ("", op.ParameterOrderString, "#co11");
  443. Assert.AreEqual (0, op.Faults.Count, "#co12");
  444. //OperationMessages
  445. Assert.AreEqual (2, op.Messages.Count, "#co13");
  446. Assert.AreEqual (OperationFlow.RequestResponse, op.Messages.Flow, "#co14");
  447. CheckOperationMessage (op.Messages [0], "http://myns/echo:IEchoService_DoubleIt_InputMessage", typeof (OperationInput), "http://myns/echo/IEchoService/DoubleIt");
  448. CheckOperationMessage (op.Messages [1], "http://myns/echo:IEchoService_DoubleIt_OutputMessage", typeof (OperationOutput), "http://myns/echo/IEchoService/DoubleItResponse");
  449. /* FIXME: Assert.AreEqual (1, wsd.Types.Schemas.Count, "#co20");
  450. XmlSchema xs = wsd.Types.Schemas [0];
  451. Assert.AreEqual (4, xs.Includes.Count);
  452. //FIXME: Check the imports.. */
  453. }
  454. void CheckOperationMessage (OperationMessage opmsg, string msg, Type type, string action)
  455. {
  456. Assert.AreEqual (type, opmsg.GetType (), "#com1");
  457. Assert.AreEqual (msg, opmsg.Message.ToString (), "#com2");
  458. Assert.AreEqual (0, opmsg.Extensions.Count, "#com3");
  459. Assert.AreEqual (1, opmsg.ExtensibleAttributes.Length, "#com4");
  460. Assert.IsNull (opmsg.Name, "#com5");
  461. XmlAttribute attr = opmsg.ExtensibleAttributes [0];
  462. Assert.AreEqual ("Action", attr.LocalName, "#ca1");
  463. Assert.AreEqual ("http://www.w3.org/2006/05/addressing/wsdl", attr.NamespaceURI, "#ca2");
  464. Assert.AreEqual (action, attr.Value, "#ca3");
  465. }
  466. void CheckMessage (WSServiceDescription sd, string msg_name, string part_type)
  467. {
  468. CheckMessage (sd, msg_name, "parameters", part_type, false, "");
  469. }
  470. void CheckMessage (WSServiceDescription sd, string msg_name, string part_name, string part_type, bool is_type, string label)
  471. {
  472. WSMessage m = sd.Messages [msg_name];
  473. Assert.IsNotNull (m, label + " : Message named " + msg_name + " not found.");
  474. Assert.AreEqual (msg_name, m.Name, label + " #cm1");
  475. Assert.AreEqual (0, m.Extensions.Count, label + " #cm2");
  476. Assert.IsNull (m.ExtensibleAttributes, label + " #cm3a");
  477. Assert.AreEqual (1, m.Parts.Count, label + " #cm3");
  478. Assert.AreEqual (part_name, m.Parts [0].Name, label + " #cm9");
  479. if (is_type) {
  480. Assert.AreEqual ("", m.Parts [0].Element.ToString (), label + " #cm4");
  481. Assert.AreEqual (part_type, m.Parts [0].Type.ToString (), label + " #cm4a");
  482. } else {
  483. Assert.AreEqual ("", m.Parts [0].Type.ToString (), label + " #cm5");
  484. Assert.AreEqual (part_type, m.Parts [0].Element.ToString (), label + " #cm5a");
  485. }
  486. Assert.IsNull (m.Parts [0].ExtensibleAttributes, label + " #cm6");
  487. Assert.AreEqual (0, m.Parts [0].Extensions.Count, label + " #cm7");
  488. }
  489. void WriteTo (WsdlExporter we, string name)
  490. {
  491. using (XmlTextWriter xw = new XmlTextWriter (name, Encoding.UTF8)) {
  492. xw.Formatting = Formatting.Indented;
  493. we.GetGeneratedMetadata ().WriteTo (xw);
  494. }
  495. }
  496. [Test]
  497. public void ExportEndpointTest5 () {
  498. WsdlExporter we = new WsdlExporter ();
  499. ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (IEchoService)));
  500. se.Binding = new BasicHttpBinding ();
  501. se.Address = new EndpointAddress ("http://localhost:8080");
  502. we.ExportEndpoint (se);
  503. MetadataSet ms = we.GetGeneratedMetadata ();
  504. Assert.AreEqual (6, ms.MetadataSections.Count);
  505. WSServiceDescription wsd = GetServiceDescription (ms, "http://tempuri.org/", "ExportEndpointTest5#1");
  506. SoapBinding soapBinding = (SoapBinding) wsd.Bindings [0].Extensions [0];
  507. Assert.AreEqual (SoapBindingStyle.Document, soapBinding.Style, "soapBinding.Style");
  508. Assert.AreEqual (SoapBinding.HttpTransport, soapBinding.Transport, "soapBinding.Transport");
  509. }
  510. }
  511. [DataContract]
  512. public class dc
  513. {
  514. [DataMember]
  515. string foo;
  516. /* [DataMember]
  517. dc me;
  518. [DataMember]
  519. some_enum en;
  520. [DataMember]
  521. NotReferenced nr;*/
  522. [DataMember]
  523. public FooNS.bar bb;
  524. }
  525. [ServiceContract (Namespace = "http://myns/echo")]
  526. public interface IEchoService
  527. {
  528. [OperationContract]
  529. string Echo (string msg, int num, dc d);
  530. [OperationContract]
  531. void DoubleIt (int it, string prefix);
  532. /*[OperationContract]
  533. void foo ();*/
  534. }
  535. [ServiceContract (Name = "ThisIsEchoService")]
  536. public interface IEchoService2
  537. {
  538. [OperationContract]
  539. string Echo (string msg, int num, dc d);
  540. [OperationContract (IsOneWay = true)]
  541. void DoubleIt (int it, string prefix);
  542. /*[OperationContract]
  543. void foo ();*/
  544. }
  545. [ServiceContract (Name = "AnotherService")]
  546. public interface IEchoService3
  547. {
  548. [OperationContract]
  549. string Echo (string msg, int num, dc d);
  550. [OperationContract (IsOneWay = true)]
  551. void DoubleIt (int it, string prefix);
  552. /*[OperationContract]
  553. void foo ();*/
  554. }
  555. [ServiceContract]
  556. public class Bar1
  557. {
  558. [OperationContract]
  559. public void Foo (SMMessage msg, string s)
  560. {
  561. }
  562. }
  563. [ServiceContract]
  564. public interface IFoo1
  565. {
  566. //Same DataContract used in different operations
  567. [OperationContract]
  568. void Op1 (dc d);
  569. [OperationContract]
  570. void Op2 (dc d);
  571. }
  572. //Used to check whether both IFoo1 & IFoo1a
  573. //can be exported
  574. //Operations are not Service scoped
  575. [ServiceContract]
  576. public interface IFoo1a
  577. {
  578. [OperationContract]
  579. void Op1 (string s);
  580. }
  581. [ServiceContract]
  582. public interface IFoo2
  583. {
  584. // FIXME: it does not pass yet
  585. [OperationContract]
  586. OregoMessage Nanoda (OregoMessage msg);
  587. // FIXME: it does not pass yet
  588. [OperationContract]
  589. Mona NewMona (Mona source);
  590. }
  591. [MessageContract]
  592. public class OregoMessage
  593. {
  594. [MessageBodyMember]
  595. public string Neutral;
  596. [MessageBodyMember]
  597. public Assembly Huh;
  598. [MessageBodyMember] // it should be ignored ...
  599. public string Setter { set { } }
  600. public string NonMember;
  601. }
  602. [DataContract]
  603. public class Mona
  604. {
  605. [DataMember]
  606. public string OmaeMona;
  607. [DataMember]
  608. public string OreMona;
  609. }
  610. }
  611. namespace FooNS
  612. {
  613. [DataContract]
  614. public class bar
  615. {
  616. [DataMember]
  617. public string foo;
  618. }
  619. }