| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- //
- // System.Web.Services.Protocols.SoapHttpClientProtocolTest.cs
- //
- // Author:
- // Gert Driesen <[email protected]>
- //
- // (C) 2007 Gert Driesen
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Web.Services;
- using System.Web.Services.Description;
- using System.Web.Services.Protocols;
- using System.Xml;
- using System.Xml.Serialization;
- using NUnit.Framework;
- namespace MonoTests.System.Web.Services.Protocols
- {
- [TestFixture]
- public class SoapHttpClientProtocolTest
- {
- [Ignore ("this kind of connection oriented tests got non-working after some Windows updates in .NET 2.0 (1.1 still works).")]
- [Test] // bug #79988
- public void OutParametersTest ()
- {
- IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000);
- using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (OutParametersResponse))) {
- sr.Start ();
- FooService service = new FooService ();
- service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/";
- int a;
- bool b;
- Elem [] e = service.Req ("x", out a, out b);
- Assert.IsNull (e, "#A1");
- Assert.AreEqual (0, a, "#A2");
- Assert.IsFalse (b, "#A3");
- service.Dispose ();
- sr.Stop ();
- }
- }
- [Ignore ("this kind of connection oriented tests got non-working after some Windows updates in .NET 2.0 (1.1 still works).")]
- [Test] // bug #81886
- public void FaultTest ()
- {
- IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000);
- using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (FaultResponse_Qualified))) {
- sr.Start ();
- FooService service = new FooService ();
- service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/";
- try {
- service.Run ();
- Assert.Fail ("#A1");
- } catch (SoapException ex) {
- Assert.AreEqual ("Mono Web Service", ex.Actor, "#A2");
- Assert.AreEqual (SoapException.ServerFaultCode, ex.Code, "#A3");
- Assert.IsNotNull (ex.Detail, "#A4");
- Assert.AreEqual ("detail", ex.Detail.LocalName, "#A5");
- Assert.AreEqual ("http://schemas.xmlsoap.org/soap/envelope/", ex.Detail.NamespaceURI, "#A6");
- XmlNamespaceManager nsMgr = new XmlNamespaceManager (ex.Detail.OwnerDocument.NameTable);
- nsMgr.AddNamespace ("se", "http://www.mono-project/System");
- XmlElement systemError = (XmlElement) ex.Detail.SelectSingleNode (
- "se:systemerror", nsMgr);
- Assert.IsNotNull (systemError, "#A7");
- Assert.IsNull (ex.InnerException, "#A8");
- Assert.AreEqual ("Failure processing request.", ex.Message, "#A9");
- }
- service.Dispose ();
- sr.Stop ();
- }
- using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (FaultResponse_Unqualified))) {
- sr.Start ();
- FooService service = new FooService ();
- service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/";
- try {
- service.Run ();
- Assert.Fail ("#B1");
- } catch (SoapException ex) {
- Assert.AreEqual ("Mono Web Service", ex.Actor, "#B2");
- Assert.AreEqual (SoapException.ServerFaultCode, ex.Code, "#B3");
- Assert.IsNotNull (ex.Detail, "#B4");
- Assert.AreEqual ("detail", ex.Detail.LocalName, "#B5");
- Assert.AreEqual (string.Empty, ex.Detail.NamespaceURI, "#B6");
- XmlNamespaceManager nsMgr = new XmlNamespaceManager (ex.Detail.OwnerDocument.NameTable);
- nsMgr.AddNamespace ("se", "http://www.mono-project/System");
- XmlElement systemError = (XmlElement) ex.Detail.SelectSingleNode (
- "se:systemerror", nsMgr);
- Assert.IsNotNull (systemError, "#B7");
- Assert.IsNull (ex.InnerException, "#B8");
- Assert.AreEqual ("Failure processing request.", ex.Message, "#B9");
- }
- service.Dispose ();
- sr.Stop ();
- }
- }
- static byte [] FaultResponse_Qualified (Socket socket)
- {
- string responseContent =
- "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
- " <soap:Body>" +
- " <soap:Fault>" +
- " <soap:faultcode>soap:Server</soap:faultcode>" +
- " <soap:faultstring>Failure processing request.</soap:faultstring>" +
- " <soap:faultactor>Mono Web Service</soap:faultactor>" +
- " <soap:detail>" +
- " <se:systemerror xmlns:se=\"http://www.mono-project/System\">" +
- " <se:code>5000</se:code>" +
- " <se:description>Invalid credentials.</se:description>" +
- " </se:systemerror>" +
- " </soap:detail>" +
- " </soap:Fault>" +
- " </soap:Body>" +
- "</soap:Envelope>";
- StringWriter sw = new StringWriter ();
- sw.WriteLine ("HTTP/1.1 200 OK");
- sw.WriteLine ("Content-Type: text/xml");
- sw.WriteLine ("Content-Length: " + responseContent.Length);
- sw.WriteLine ();
- sw.Write (responseContent);
- sw.Flush ();
- return Encoding.UTF8.GetBytes (sw.ToString ());
- }
- static byte [] FaultResponse_Unqualified (Socket socket)
- {
- string responseContent =
- "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
- " <soap:Body>" +
- " <soap:Fault>" +
- " <faultcode>soap:Server</faultcode>" +
- " <faultstring>Failure processing request.</faultstring>" +
- " <faultactor>Mono Web Service</faultactor>" +
- " <detail>" +
- " <se:systemerror xmlns:se=\"http://www.mono-project/System\">" +
- " <se:code>5000</se:code>" +
- " <se:description>Invalid credentials.</se:description>" +
- " </se:systemerror>" +
- " </detail>" +
- " </soap:Fault>" +
- " </soap:Body>" +
- "</soap:Envelope>";
- StringWriter sw = new StringWriter ();
- sw.WriteLine ("HTTP/1.1 200 OK");
- sw.WriteLine ("Content-Type: text/xml");
- sw.WriteLine ("Content-Length: " + responseContent.Length);
- sw.WriteLine ();
- sw.Write (responseContent);
- sw.Flush ();
- return Encoding.UTF8.GetBytes (sw.ToString ());
- }
- static byte [] OutParametersResponse (Socket socket)
- {
- string responseContent =
- "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
- " <soap:Body>" +
- " <ReqResponse2 xmlns=\"urn:foo\">" +
- " <Hits>ERERE</Hits>" +
- " </ReqResponse2>" +
- " </soap:Body>" +
- "</soap:Envelope>";
- StringWriter sw = new StringWriter ();
- sw.WriteLine ("HTTP/1.1 200 OK");
- sw.WriteLine ("Content-Type: text/xml");
- sw.WriteLine ("Content-Length: " + responseContent.Length);
- sw.WriteLine ();
- sw.Write (responseContent);
- sw.Flush ();
- return Encoding.UTF8.GetBytes (sw.ToString ());
- }
- [WebServiceBindingAttribute (Name = "Foo", Namespace = "urn:foo")]
- public class FooService : SoapHttpClientProtocol
- {
- [SoapDocumentMethodAttribute ("", RequestElementName = "Req", RequestNamespace = "urn:foo", ResponseNamespace = "urn:foo", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
- [return: XmlElementAttribute ("Hits")]
- public Elem [] Req ([XmlAttributeAttribute ()] string arg, [XmlAttributeAttribute ()] out int status, [XmlAttributeAttribute ()] [XmlIgnoreAttribute ()] out bool statusSpecified)
- {
- object [] results = this.Invoke ("Req", new object [] { arg });
- status = ((int) (results [1]));
- statusSpecified = ((bool) (results [2]));
- return ((Elem []) (results [0]));
- }
- [SoapDocumentMethodAttribute ("", RequestElementName = "Run", RequestNamespace = "urn:foo", ResponseNamespace = "urn:foo", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
- [return: XmlElementAttribute ("Hits")]
- public Elem Run ()
- {
- this.Invoke ("Run", new object [0]);
- return new Elem ();
- }
- }
- [SerializableAttribute ()]
- public class Elem
- {
- private string attrField;
- [XmlAttributeAttribute ()]
- public string attr
- {
- get
- {
- return this.attrField;
- }
- set
- {
- this.attrField = value;
- }
- }
- }
- }
- }
|