SoapHttpClientProtocolTest.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // System.Web.Services.Protocols.SoapHttpClientProtocolTest.cs
  3. //
  4. // Author:
  5. // Gert Driesen <[email protected]>
  6. //
  7. // (C) 2007 Gert Driesen
  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.Net;
  30. using System.Web.Services;
  31. using System.Web.Services.Description;
  32. using System.Web.Services.Protocols;
  33. using System.Xml.Serialization;
  34. using NUnit.Framework;
  35. namespace System.Web.Services.Protocols
  36. {
  37. [TestFixture]
  38. public class SoapHttpClientProtocolTest
  39. {
  40. [Test] // bug #79988
  41. public void OutParametersTest ()
  42. {
  43. IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000);
  44. using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (Response_OutParametersTest))) {
  45. sr.Start ();
  46. FooService service = new FooService ();
  47. service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/";
  48. int a;
  49. bool b;
  50. Elem [] e = service.Req ("x", out a, out b);
  51. Assert.IsNull (e, "#A1");
  52. Assert.AreEqual (0, a, "#A2");
  53. Assert.IsFalse (b, "#A3");
  54. }
  55. }
  56. static string Response_OutParametersTest ()
  57. {
  58. return "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
  59. "<soap:Body>" +
  60. "<ReqResponse2 xmlns=\"urn:foo\">" +
  61. "<Hits>ERERE</Hits>" +
  62. "</ReqResponse2>" +
  63. "</soap:Body>" +
  64. "</soap:Envelope>";
  65. }
  66. [WebServiceBindingAttribute (Name = "Foo", Namespace = "urn:foo")]
  67. public class FooService : SoapHttpClientProtocol
  68. {
  69. [SoapDocumentMethodAttribute ("", RequestElementName = "Req", RequestNamespace = "urn:foo", ResponseNamespace = "urn:foo", Use = SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
  70. [return: XmlElementAttribute ("Hits")]
  71. public Elem [] Req ([XmlAttributeAttribute ()] string arg, [XmlAttributeAttribute ()] out int status, [XmlAttributeAttribute ()] [XmlIgnoreAttribute ()] out bool statusSpecified)
  72. {
  73. object [] results = this.Invoke ("Req", new object [] { arg });
  74. status = ((int) (results [1]));
  75. statusSpecified = ((bool) (results [2]));
  76. return ((Elem []) (results [0]));
  77. }
  78. }
  79. [SerializableAttribute ()]
  80. public class Elem
  81. {
  82. private string attrField;
  83. [XmlAttributeAttribute ()]
  84. public string attr
  85. {
  86. get
  87. {
  88. return this.attrField;
  89. }
  90. set
  91. {
  92. this.attrField = value;
  93. }
  94. }
  95. }
  96. }
  97. }