Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class AddressHeaderTest
{
[Test]
public void WriteAddressHeaderTest ()
{
AddressHeader h = AddressHeader.CreateAddressHeader (1);
StringWriter sw = new StringWriter ();
XmlWriterSettings s = new XmlWriterSettings ();
s.OmitXmlDeclaration = true;
XmlWriter w = XmlWriter.Create (sw, s);
h.WriteAddressHeader (w);
w.Close ();
Assert.AreEqual (
@"<int xmlns=""http://schemas.microsoft.com/2003/10/Serialization/"">1</int>",
sw.ToString ());
}
[Test]
public void CreateAddressHeader ()
{
AddressHeader h = AddressHeader.CreateAddressHeader ("foo", "urn:foo", null);
}
[Test]
[Category ("NotDotNet")]
// It should work, but MS implementation expects body to be
// IComparable.
public void EqualsTest ()
{
AddressHeader h = AddressHeader.CreateAddressHeader (
"foo", "urn:foo", null);
AddressHeader h2 = AddressHeader.CreateAddressHeader (
"foo", "urn:foo", null);
Assert.IsFalse (h.Equals (null), "#1"); // never throw nullref
Assert.IsTrue (h.Equals (h2), "#2");
}
[Test]
public void GetAddressHeaderReader ()
{
var h = AddressHeader.CreateAddressHeader ("foo", String.Empty, null);
var r = h.GetAddressHeaderReader ();
r.MoveToContent ();
Assert.AreEqual ("foo", r.LocalName, "#1");
Assert.AreEqual ("true", r.GetAttribute ("nil", XmlSchema.InstanceNamespace), "#2");
}
[Test]
public void WriteAddressHeader ()
{
var h = AddressHeader.CreateAddressHeader ("foo", "urn:foo", null);
var sw = new StringWriter ();
var xw = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw));
h.WriteAddressHeader (xw);
xw.Close ();
Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?><foo i:nil=\"true\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:foo\" />", sw.ToString (), "#1");
}
}
}

View File

@@ -0,0 +1,64 @@
//
// AddressingVersionTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// 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.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using NUnit.Framework;
using Element = System.ServiceModel.Channels.TextMessageEncodingBindingElement;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class AddressingVersionTest
{
[Test]
public void Equality ()
{
Assert.AreEqual (AddressingVersion.WSAddressing10,
MessageVersion.Default.Addressing, "#1");
Assert.IsTrue (AddressingVersion.WSAddressing10 ==
MessageVersion.Default.Addressing, "#2");
Assert.IsTrue (Object.ReferenceEquals (
AddressingVersion.WSAddressing10,
MessageVersion.Default.Addressing), "#3");
}
[Test]
public void Constants ()
{
Assert.AreEqual ("Addressing10 (http://www.w3.org/2005/08/addressing)",
AddressingVersion.WSAddressing10.ToString (), "#1");
Assert.AreEqual ("Addressing200408 (http://schemas.xmlsoap.org/ws/2004/08/addressing)",
AddressingVersion.WSAddressingAugust2004.ToString (), "#2");
}
}
}

View File

@@ -0,0 +1,258 @@
//
// AsymmetricSecurityBindingElementTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
using System.Threading;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class AsymmetricSecurityBindingElementTest
{
static X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.pfx", "mono");
static X509Certificate2 cert2 = new X509Certificate2 ("Test/Resources/test.cer");
// InitiatorTokenParameters should have asymmetric key.
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Category ("NotWorking")] // this test unnecessarily requires some internal processing order
public void ClientInitiatorHasNoKeys1 ()
{
ClientInitiatorHasNoKeysCore (false, MessageProtectionOrder.SignBeforeEncrypt);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Category ("NotWorking")] // this test unnecessarily requires some internal processing order
public void ClientInitiatorHasNoKeys2 ()
{
ClientInitiatorHasNoKeysCore (true, MessageProtectionOrder.SignBeforeEncrypt);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Category ("NotWorking")] // this test unnecessarily requires some internal processing order
public void ClientInitiatorHasNoKeys3 ()
{
ClientInitiatorHasNoKeysCore (false, MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Category ("NotWorking")] // this test unnecessarily requires some internal processing order
public void ClientInitiatorHasNoKeys4 ()
{
ClientInitiatorHasNoKeysCore (true, MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature);
}
public void ClientInitiatorHasNoKeysCore (bool deriveKeys, MessageProtectionOrder order)
{
AsymmetricSecurityBindingElement sbe =
new AsymmetricSecurityBindingElement ();
sbe.InitiatorTokenParameters =
new UserNameSecurityTokenParameters ();
sbe.RecipientTokenParameters =
new X509SecurityTokenParameters ();
sbe.SetKeyDerivation (deriveKeys);
sbe.MessageProtectionOrder = order;
TransportBindingElement tbe = new HandlerTransportBindingElement (delegate (Message input) {
// funky, but .NET does not raise an error
// until it writes the message to somewhere.
// That is, it won't raise an error if this
// HandlerTransportBindingElement does not
// write the input message to somewhere.
// It is an obvious bug.
input.WriteMessage (XmlWriter.Create (TextWriter.Null));
throw new Exception ();
});
CustomBinding binding = new CustomBinding (sbe, tbe);
EndpointAddress address = new EndpointAddress (
new Uri ("stream:dummy"),
new X509CertificateEndpointIdentity (cert2));
CalcProxy proxy = new CalcProxy (binding, address);
proxy.ClientCredentials.UserName.UserName = "mono";
proxy.Open ();
// Until here the wrong parameters are not checked.
proxy.Sum (1, 2);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
[Category ("NotWorking")]
public void ServiceRecipientHasNoKeys ()
{
AsymmetricSecurityBindingElement sbe =
new AsymmetricSecurityBindingElement ();
sbe.InitiatorTokenParameters =
new X509SecurityTokenParameters ();
sbe.RecipientTokenParameters =
new UserNameSecurityTokenParameters ();
//sbe.SetKeyDerivation (false);
//sbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
CustomBinding binding = new CustomBinding (sbe,
new HttpTransportBindingElement ());
IChannelListener<IReplyChannel> l =
binding.BuildChannelListener<IReplyChannel> (new Uri ("http://localhost:37564"), new BindingParameterCollection ());
try {
l.Open ();
} finally {
if (l.State == CommunicationState.Opened)
l.Close ();
}
}
Message tmp_request, tmp_reply;
[Test]
[ExpectedException (typeof (MessageSecurityException))]
// after having to fix several issues, I forgot what I originally wanted to test here ...
[Ignore ("It causes some weird failure and port blocking ...")]
public void VerifyX509MessageSecurityAtService ()
{
AsymmetricSecurityBindingElement clisbe =
new AsymmetricSecurityBindingElement ();
clisbe.InitiatorTokenParameters =
new X509SecurityTokenParameters ();
clisbe.RecipientTokenParameters =
new X509SecurityTokenParameters ();
AsymmetricSecurityBindingElement svcsbe =
new AsymmetricSecurityBindingElement ();
svcsbe.InitiatorTokenParameters =
new X509SecurityTokenParameters ();
svcsbe.RecipientTokenParameters =
new X509SecurityTokenParameters ();
CustomBinding b_req = new CustomBinding (clisbe,
new HttpTransportBindingElement ());
b_req.ReceiveTimeout = b_req.SendTimeout = TimeSpan.FromSeconds (10);
CustomBinding b_res = new CustomBinding (svcsbe, new HttpTransportBindingElement ());
b_res.ReceiveTimeout = b_res.SendTimeout = TimeSpan.FromSeconds (10);
EndpointAddress remaddr = new EndpointAddress (
new Uri ("http://localhost:37564"),
new X509CertificateEndpointIdentity (cert2));
CalcProxy proxy = null;
ServiceHost host = new ServiceHost (typeof (CalcService));
host.AddServiceEndpoint (typeof (ICalc), b_res, "http://localhost:37564");
ServiceCredentials cred = new ServiceCredentials ();
cred.ServiceCertificate.Certificate = cert;
host.Description.Behaviors.Add (cred);
try {
host.Open ();
proxy = new CalcProxy (b_req, remaddr);
proxy.ClientCredentials.ClientCertificate.Certificate = cert;
// FIXME: on WinFX, when this Begin method
// is invoked before the listener setup, it
// somehow works, while ours doesn't.
//IAsyncResult result = proxy.BeginSum (1, 2, null, null);
//Assert.AreEqual (3, proxy.EndSum (result));
Assert.AreEqual (3, proxy.Sum (1, 2));
} finally {
if (host.State == CommunicationState.Opened)
host.Close ();
}
}
[Test]
public void SetKeyDerivation ()
{
AsymmetricSecurityBindingElement be;
X509SecurityTokenParameters p, p2;
be = new AsymmetricSecurityBindingElement ();
p = new X509SecurityTokenParameters ();
p2 = new X509SecurityTokenParameters ();
be.InitiatorTokenParameters = p;
be.RecipientTokenParameters = p2;
be.SetKeyDerivation (false);
Assert.AreEqual (false, p.RequireDerivedKeys, "#1");
Assert.AreEqual (false, p2.RequireDerivedKeys, "#2");
be = new AsymmetricSecurityBindingElement ();
p = new X509SecurityTokenParameters ();
p2 = new X509SecurityTokenParameters ();
be.SetKeyDerivation (false); // set in prior - makes no sense
be.InitiatorTokenParameters = p;
be.RecipientTokenParameters = p2;
Assert.AreEqual (true, p.RequireDerivedKeys, "#3");
Assert.AreEqual (true, p2.RequireDerivedKeys, "#4");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Category ("NotWorking")]
public void RejectInclusionModeNever ()
{
AsymmetricSecurityBindingElement sbe =
new AsymmetricSecurityBindingElement ();
sbe.InitiatorTokenParameters = sbe.RecipientTokenParameters =
new X509SecurityTokenParameters (
X509KeyIdentifierClauseType.Thumbprint,
// this leads to the failure.
SecurityTokenInclusionMode.Never);
ServiceHost host = new ServiceHost (typeof (Foo));
HttpTransportBindingElement hbe =
new HttpTransportBindingElement ();
CustomBinding binding = new CustomBinding (sbe, hbe);
host.AddServiceEndpoint (typeof (IFoo),
binding, new Uri ("http://localhost:37564"));
ServiceCredentials cred = new ServiceCredentials ();
cred.ServiceCertificate.Certificate =
new X509Certificate2 ("Test/Resources/test.pfx", "mono");
cred.ClientCertificate.Authentication.CertificateValidationMode =
X509CertificateValidationMode.None;
host.Description.Behaviors.Add (cred);
try {
host.Open ();
} finally {
if (host.State == CommunicationState.Opened)
host.Close ();
}
}
}
}

View File

@@ -0,0 +1,459 @@
//
// BinaryMessageEncodingBindingElementTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 Novell, Inc. http://www.novell.com
//
// 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.Collections.ObjectModel;
using System.IO;
using System.Net.Sockets;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
using NUnit.Framework;
using Element = System.ServiceModel.Channels.BinaryMessageEncodingBindingElement;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class BinaryMessageEncodingBindingElementTest
{
[Test]
public void DefaultValues ()
{
Element el = new Element ();
Assert.AreEqual (64, el.MaxReadPoolSize, "#1");
Assert.AreEqual (16, el.MaxWritePoolSize, "#2");
Assert.AreEqual (MessageVersion.Default, el.MessageVersion, "#3");
// FIXME: test ReaderQuotas
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void BuildChannelListenerNullArg ()
{
new Element ().BuildChannelListener<IReplyChannel> (null);
}
[Test]
public void CanBuildChannelFactory ()
{
CustomBinding cb = new CustomBinding (
new HttpTransportBindingElement ());
BindingContext ctx = new BindingContext (
cb, new BindingParameterCollection ());
Element el = new Element ();
Assert.IsTrue (el.CanBuildChannelFactory<IRequestChannel> (ctx), "#1");
Assert.IsFalse (el.CanBuildChannelFactory<IRequestSessionChannel> (ctx), "#2");
}
[Test]
public void BuildChannelFactory ()
{
CustomBinding cb = new CustomBinding (
new HttpTransportBindingElement ());
BindingContext ctx = new BindingContext (
cb, new BindingParameterCollection ());
Element el = new Element ();
IChannelFactory<IRequestChannel> cf =
el.BuildChannelFactory<IRequestChannel> (ctx);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void BuildChannelListenerEmptyCustomBinding ()
{
CustomBinding cb = new CustomBinding ();
BindingContext ctx = new BindingContext (
cb, new BindingParameterCollection ());
new Element ().BuildChannelListener<IReplyChannel> (ctx);
}
[Test]
public void BuildChannelListenerWithTransport ()
{
CustomBinding cb = new CustomBinding (
new HttpTransportBindingElement ());
BindingContext ctx = new BindingContext (
cb, new BindingParameterCollection (),
new Uri ("http://localhost:8080"), String.Empty, ListenUriMode.Unique);
new Element ().BuildChannelListener<IReplyChannel> (ctx);
}
[Test]
[ExpectedException (typeof (ProtocolException))]
public void ReadMessageWrongContentType ()
{
var encoder = new BinaryMessageEncodingBindingElement ().CreateMessageEncoderFactory ().Encoder;
encoder.ReadMessage (new MemoryStream (new byte [0]), 100, "application/octet-stream");
}
[Test]
public void ReadMessage ()
{
using (var ms = File.OpenRead ("Test/System.ServiceModel.Channels/binary-message.raw")) {
var session = new XmlBinaryReaderSession ();
byte [] rsbuf = new BinaryFrameSupportReader (ms).ReadSizedChunk ();
int count = 0;
using (var rms = new MemoryStream (rsbuf, 0, rsbuf.Length)) {
var rbr = new BinaryReader (rms, Encoding.UTF8);
while (rms.Position < rms.Length)
session.Add (count++, rbr.ReadString ());
}
var xr = XmlDictionaryReader.CreateBinaryReader (ms, BinaryFrameSupportReader.soap_dictionary, new XmlDictionaryReaderQuotas (), session);
string soapNS = "http://www.w3.org/2003/05/soap-envelope";
string addrNS = "http://www.w3.org/2005/08/addressing";
string xmlnsNS = "http://www.w3.org/2000/xmlns/";
string peerNS = "http://schemas.microsoft.com/net/2006/05/peer";
xr.MoveToContent ();
AssertNode (xr, 0, XmlNodeType.Element, "s", "Envelope", soapNS, String.Empty, "#1");
Assert.AreEqual (2, xr.AttributeCount, "#1-1-1");
Assert.IsTrue (xr.MoveToAttribute ("s", xmlnsNS), "#1-2");
AssertNode (xr, 1, XmlNodeType.Attribute, "xmlns", "s", xmlnsNS, soapNS, "#2");
Assert.IsTrue (xr.MoveToAttribute ("a", xmlnsNS), "#2-2");
AssertNode (xr, 1, XmlNodeType.Attribute, "xmlns", "a", xmlnsNS, addrNS, "#3");
Assert.IsTrue (xr.Read (), "#3-2");
AssertNode (xr, 1, XmlNodeType.Element, "s", "Header", soapNS, String.Empty, "#4");
Assert.IsTrue (xr.Read (), "#4-2");
AssertNode (xr, 2, XmlNodeType.Element, "a", "Action", addrNS, String.Empty, "#5");
Assert.IsTrue (xr.MoveToAttribute ("mustUnderstand", soapNS), "#5-2");
AssertNode (xr, 3, XmlNodeType.Attribute, "s", "mustUnderstand", soapNS, "1", "#6");
Assert.IsTrue (xr.Read (), "#6-2");
AssertNode (xr, 3, XmlNodeType.Text, "", "", "", "http://schemas.microsoft.com/net/2006/05/peer/resolver/Resolve", "#7");
Assert.IsTrue (xr.Read (), "#7-2");
AssertNode (xr, 2, XmlNodeType.EndElement, "a", "Action", addrNS, String.Empty, "#8");
Assert.IsTrue (xr.Read (), "#8-2");
AssertNode (xr, 2, XmlNodeType.Element, "a", "MessageID", addrNS, String.Empty, "#9");
Assert.IsTrue (xr.Read (), "#9-2");
Assert.AreEqual (XmlNodeType.Text, xr.NodeType, "#10");
Assert.IsTrue (xr.Read (), "#10-2");
AssertNode (xr, 2, XmlNodeType.EndElement, "a", "MessageID", addrNS, String.Empty, "#11");
Assert.IsTrue (xr.Read (), "#11-2"); // -> a:ReplyTo
AssertNode (xr, 2, XmlNodeType.Element, "a", "ReplyTo", addrNS, String.Empty, "#12");
xr.Skip (); // -> a:To
AssertNode (xr, 2, XmlNodeType.Element, "a", "To", addrNS, String.Empty, "#13");
xr.Skip (); // -> /s:Header
AssertNode (xr, 1, XmlNodeType.EndElement, "s", "Header", soapNS, String.Empty, "#14");
Assert.IsTrue (xr.Read (), "#14-2");
AssertNode (xr, 1, XmlNodeType.Element, "s", "Body", soapNS, String.Empty, "#15");
Assert.IsTrue (xr.Read (), "#15-2");
AssertNode (xr, 2, XmlNodeType.Element, "", "Resolve", peerNS, String.Empty, "#16");
Assert.IsTrue (xr.MoveToAttribute ("xmlns"), "#16-2");
AssertNode (xr, 3, XmlNodeType.Attribute, "", "xmlns", xmlnsNS, peerNS, "#17");
Assert.IsTrue (xr.Read (), "#17-2");
AssertNode (xr, 3, XmlNodeType.Element, "", "ClientId", peerNS, String.Empty, "#18");
/*
while (!xr.EOF) {
xr.Read ();
Console.WriteLine ("{0}: {1}:{2} {3} {4}", xr.NodeType, xr.Prefix, xr.LocalName, xr.NamespaceURI, xr.Value);
for (int i = 0; i < xr.AttributeCount; i++) {
xr.MoveToAttribute (i);
Console.WriteLine (" Attribute: {0}:{1} {2} {3}", xr.Prefix, xr.LocalName, xr.NamespaceURI, xr.Value);
}
}
*/
}
}
[Test]
public void ConnectionTcpTransport ()
{
var host = new ServiceHost (typeof (Foo));
var bindingsvc = new CustomBinding (new BindingElement [] {
new BinaryMessageEncodingBindingElement (),
new TcpTransportBindingElement () });
host.AddServiceEndpoint (typeof (IFoo), bindingsvc, "net.tcp://localhost:37564/");
host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().IncludeExceptionDetailInFaults = true;
host.Open (TimeSpan.FromSeconds (5));
try {
for (int i = 0; i < 2; i++) {
var bindingcli = new NetTcpBinding ();
bindingcli.Security.Mode = SecurityMode.None;
var cli = new ChannelFactory<IFooClient> (bindingcli, new EndpointAddress ("net.tcp://localhost:37564/")).CreateChannel ();
Assert.AreEqual ("test for echo", cli.Echo ("TEST FOR ECHO"), "#1");
var sid = cli.SessionId;
Assert.AreEqual (3000, cli.Add (1000, 2000), "#2");
Assert.AreEqual (sid, cli.SessionId, "#3");
cli.Close ();
}
} finally {
host.Close (TimeSpan.FromSeconds (5));
var t = new TcpListener (37564);
t.Start ();
t.Stop ();
}
}
[Test]
public void ConnectionHttpTransport ()
{
var host = new ServiceHost (typeof (Foo));
var bindingsvc = new CustomBinding (new BindingElement [] {
new BinaryMessageEncodingBindingElement (),
new HttpTransportBindingElement () });
host.AddServiceEndpoint (typeof (IFoo), bindingsvc, "http://localhost:37564/");
host.Description.Behaviors.Find<ServiceBehaviorAttribute> ().IncludeExceptionDetailInFaults = true;
host.Open (TimeSpan.FromSeconds (5));
try {
for (int i = 0; i < 2; i++) {
var bindingcli = new CustomBinding (new BindingElement [] {
new BinaryMessageEncodingBindingElement (),
new HttpTransportBindingElement () });
var cli = new ChannelFactory<IFooClient> (bindingcli, new EndpointAddress ("http://localhost:37564/")).CreateChannel ();
Assert.AreEqual ("test for echo", cli.Echo ("TEST FOR ECHO"), "#1");
var sid = cli.SessionId;
Assert.AreEqual (3000, cli.Add (1000, 2000), "#2");
Assert.AreEqual (sid, cli.SessionId, "#3");
cli.Close ();
}
} finally {
host.Close (TimeSpan.FromSeconds (5));
var t = new TcpListener (37564);
t.Start ();
t.Stop ();
}
}
public interface IFooClient : IFoo, IClientChannel
{
}
[ServiceContract]
public interface IFoo
{
[OperationContract]
string Echo (string msg);
[OperationContract]
uint Add (uint v1, uint v2);
}
class Foo : IFoo
{
public string Echo (string msg)
{
return msg.ToLower ();
}
public uint Add (uint v1, uint v2)
{
return v1 + v2;
}
}
void AssertNode (XmlReader reader, int depth, XmlNodeType nodeType, string prefix, string localName, string ns, string value, string label)
{
Assert.AreEqual (nodeType, reader.NodeType, label + ".NodeType");
Assert.AreEqual (localName, reader.LocalName, label + ".LocalName");
Assert.AreEqual (prefix, reader.Prefix, label + ".Prefix");
Assert.AreEqual (ns, reader.NamespaceURI, label + ".NS");
Assert.AreEqual (value, reader.Value, label + ".Value");
Assert.AreEqual (depth, reader.Depth, label + ".Depth");
}
}
class BinaryFrameSupportReader : BinaryReader
{
public BinaryFrameSupportReader (Stream s)
: base (s)
{
}
public byte [] ReadSizedChunk ()
{
int length = Read7BitEncodedInt ();
if (length > 65536)
throw new InvalidOperationException ("The message is too large.");
byte [] buffer = new byte [length];
Read (buffer, 0, length);
return buffer;
}
// Copied from BinaryMessageEncoder.cs.
internal static XmlDictionary soap_dictionary;
// See [MC-NBFS] in Microsoft OSP. The strings are copied from the PDF, so the actual values might be wrong.
static readonly string [] dict_strings = {
"mustUnderstand", "Envelope",
"http://www.w3.org/2003/05/soap-envelope",
"http://www.w3.org/2005/08/addressing", "Header", "Action", "To", "Body", "Algorithm", "RelatesTo",
"http://www.w3.org/2005/08/addressing/anonymous", "URI", "Reference", "MessageID", "Id", "Identifier",
"http://schemas.xmlsoap.org/ws/2005/02/rm", "Transforms", "Transform", "DigestMethod", "DigestValue", "Address", "ReplyTo", "SequenceAcknowledgement", "AcknowledgementRange", "Upper", "Lower", "BufferRemaining",
"http://schemas.microsoft.com/ws/2006/05/rm",
"http://schemas.xmlsoap.org/ws/2005/02/rm/SequenceAcknowledgement", "SecurityTokenReference", "Sequence", "MessageNumber",
"http://www.w3.org/2000/09/xmldsig#",
"http://www.w3.org/2000/09/xmldsig#enveloped-signature", "KeyInfo",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
"http://www.w3.org/2001/04/xmlenc#",
"http://schemas.xmlsoap.org/ws/2005/02/sc", "DerivedKeyToken", "Nonce", "Signature", "SignedInfo", "CanonicalizationMethod", "SignatureMethod", "SignatureValue", "DataReference", "EncryptedData", "EncryptionMethod", "CipherData", "CipherValue",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Security", "Timestamp", "Created", "Expires", "Length", "ReferenceList", "ValueType", "Type", "EncryptedHeader",
"http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd", "RequestSecurityTokenResponseCollection",
"http://schemas.xmlsoap.org/ws/2005/02/trust",
"http://schemas.xmlsoap.org/ws/2005/02/trust#BinarySecret",
"http://schemas.microsoft.com/ws/2006/02/transactions", "s", "Fault", "MustUnderstand", "role", "relay", "Code", "Reason", "Text", "Node", "Role", "Detail", "Value", "Subcode", "NotUnderstood", "qname", "", "From", "FaultTo", "EndpointReference", "PortType", "ServiceName", "PortName", "ReferenceProperties", "RelationshipType", "Reply", "a",
"http://schemas.xmlsoap.org/ws/2006/02/addressingidentity", "Identity", "Spn", "Upn", "Rsa", "Dns", "X509v3Certificate",
"http://www.w3.org/2005/08/addressing/fault", "ReferenceParameters", "IsReferenceParameter",
"http://www.w3.org/2005/08/addressing/reply",
"http://www.w3.org/2005/08/addressing/none", "Metadata",
"http://schemas.xmlsoap.org/ws/2004/08/addressing",
"http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous",
"http://schemas.xmlsoap.org/ws/2004/08/addressing/fault",
"http://schemas.xmlsoap.org/ws/2004/06/addressingex", "RedirectTo", "Via",
"http://www.w3.org/2001/10/xml-exc-c14n#", "PrefixList", "InclusiveNamespaces", "ec", "SecurityContextToken", "Generation", "Label", "Offset", "Properties", "Cookie", "wsc",
"http://schemas.xmlsoap.org/ws/2004/04/sc",
"http://schemas.xmlsoap.org/ws/2004/04/security/sc/dk",
"http://schemas.xmlsoap.org/ws/2004/04/security/sc/sct",
"http://schemas.xmlsoap.org/ws/2004/04/security/trust/RST/SCT",
"http://schemas.xmlsoap.org/ws/2004/04/security/trust/RSTR/SCT", "RenewNeeded", "BadContextToken", "c",
"http://schemas.xmlsoap.org/ws/2005/02/sc/dk",
"http://schemas.xmlsoap.org/ws/2005/02/sc/sct",
"http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT",
"http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/SCT",
"http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT/Renew",
"http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/SCT/Renew",
"http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT/Cancel",
"http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/SCT/Cancel",
"http://www.w3.org/2001/04/xmlenc#aes128-cbc",
"http://www.w3.org/2001/04/xmlenc#kw-aes128",
"http://www.w3.org/2001/04/xmlenc#aes192-cbc",
"http://www.w3.org/2001/04/xmlenc#kw-aes192",
"http://www.w3.org/2001/04/xmlenc#aes256-cbc",
"http://www.w3.org/2001/04/xmlenc#kw-aes256",
"http://www.w3.org/2001/04/xmlenc#des-cbc",
"http://www.w3.org/2000/09/xmldsig#dsa-sha1",
"http://www.w3.org/2001/10/xml-exc-c14n#WithComments",
"http://www.w3.org/2000/09/xmldsig#hmac-sha1",
"http://www.w3.org/2001/04/xmldsig-more#hmac-sha256",
"http://schemas.xmlsoap.org/ws/2005/02/sc/dk/p_sha1",
"http://www.w3.org/2001/04/xmlenc#ripemd160",
"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p",
"http://www.w3.org/2000/09/xmldsig#rsa-sha1",
"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
"http://www.w3.org/2001/04/xmlenc#rsa-1_5",
"http://www.w3.org/2000/09/xmldsig#sha1",
"http://www.w3.org/2001/04/xmlenc#sha256",
"http://www.w3.org/2001/04/xmlenc#sha512",
"http://www.w3.org/2001/04/xmlenc#tripledes-cbc",
"http://www.w3.org/2001/04/xmlenc#kw-tripledes",
"http://schemas.xmlsoap.org/2005/02/trust/tlsnego#TLS_Wrap",
"http://schemas.xmlsoap.org/2005/02/trust/spnego#GSS_Wrap",
"http://schemas.microsoft.com/ws/2006/05/security", "dnse", "o", "Password", "PasswordText", "Username", "UsernameToken", "BinarySecurityToken", "EncodingType", "KeyIdentifier",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#HexBinary",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Text",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier",
"http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#GSS_Kerberosv5_AP_REQ",
"http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#GSS_Kerberosv5_AP_REQ1510",
"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID", "Assertion", "urn:oasis:names:tc:SAML:1.0:assertion",
"http://docs.oasis-open.org/wss/oasis-wss-rel-token-profile-1.0.pdf#license", "FailedAuthentication", "InvalidSecurityToken", "InvalidSecurity", "k", "SignatureConfirmation", "TokenType",
"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1",
"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey",
"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKeySHA1",
"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1",
"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0",
"http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID", "AUTH-HASH", "RequestSecurityTokenResponse", "KeySize", "RequestedTokenReference", "AppliesTo", "Authenticator", "CombinedHash", "BinaryExchange", "Lifetime", "RequestedSecurityToken", "Entropy", "RequestedProofToken", "ComputedKey", "RequestSecurityToken", "RequestType", "Context", "BinarySecret",
"http://schemas.xmlsoap.org/ws/2005/02/trust/spnego",
"http://schemas.xmlsoap.org/ws/2005/02/trust/tlsnego", "wst",
"http://schemas.xmlsoap.org/ws/2004/04/trust",
"http://schemas.xmlsoap.org/ws/2004/04/security/trust/RST/Issue",
"http://schemas.xmlsoap.org/ws/2004/04/security/trust/RSTR/Issue",
"http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue",
"http://schemas.xmlsoap.org/ws/2004/04/security/trust/CK/PSHA1",
"http://schemas.xmlsoap.org/ws/2004/04/security/trust/SymmetricKey",
"http://schemas.xmlsoap.org/ws/2004/04/security/trust/Nonce", "KeyType",
"http://schemas.xmlsoap.org/ws/2004/04/trust/SymmetricKey",
"http://schemas.xmlsoap.org/ws/2004/04/trust/PublicKey", "Claims", "InvalidRequest", "RequestFailed", "SignWith", "EncryptWith", "EncryptionAlgorithm", "CanonicalizationAlgorithm", "ComputedKeyAlgorithm", "UseKey",
"http://schemas.microsoft.com/net/2004/07/secext/WS-SPNego",
"http://schemas.microsoft.com/net/2004/07/secext/TLSNego", "t",
"http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue",
"http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue",
"http://schemas.xmlsoap.org/ws/2005/02/trust/Issue",
"http://schemas.xmlsoap.org/ws/2005/02/trust/SymmetricKey",
"http://schemas.xmlsoap.org/ws/2005/02/trust/CK/PSHA1",
"http://schemas.xmlsoap.org/ws/2005/02/trust/Nonce", "RenewTarget", "CancelTarget", "RequestedTokenCancelled", "RequestedAttachedReference", "RequestedUnattachedReference", "IssuedTokens",
"http://schemas.xmlsoap.org/ws/2005/02/trust/Renew",
"http://schemas.xmlsoap.org/ws/2005/02/trust/Cancel",
"http://schemas.xmlsoap.org/ws/2005/02/trust/PublicKey", "Access", "AccessDecision", "Advice", "AssertionID", "AssertionIDReference", "Attribute", "AttributeName", "AttributeNamespace", "AttributeStatement", "AttributeValue", "Audience", "AudienceRestrictionCondition", "AuthenticationInstant", "AuthenticationMethod", "AuthenticationStatement", "AuthorityBinding", "AuthorityKind", "AuthorizationDecisionStatement", "Binding", "Condition", "Conditions", "Decision", "DoNotCacheCondition", "Evidence", "IssueInstant", "Issuer", "Location", "MajorVersion", "MinorVersion", "NameIdentifier", "Format", "NameQualifier", "Namespace", "NotBefore", "NotOnOrAfter", "saml", "Statement", "Subject", "SubjectConfirmation", "SubjectConfirmationData", "ConfirmationMethod", "urn:oasis:names:tc:SAML:1.0:cm:holder-of-key", "urn:oasis:names:tc:SAML:1.0:cm:sender-vouches", "SubjectLocality", "DNSAddress", "IPAddress", "SubjectStatement", "urn:oasis:names:tc:SAML:1.0:am:unspecified", "xmlns", "Resource", "UserName", "urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName", "EmailName", "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", "u", "ChannelInstance",
"http://schemas.microsoft.com/ws/2005/02/duplex", "Encoding", "MimeType", "CarriedKeyName", "Recipient", "EncryptedKey", "KeyReference", "e",
"http://www.w3.org/2001/04/xmlenc#Element",
"http://www.w3.org/2001/04/xmlenc#Content", "KeyName", "MgmtData", "KeyValue", "RSAKeyValue", "Modulus", "Exponent", "X509Data", "X509IssuerSerial", "X509IssuerName", "X509SerialNumber", "X509Certificate", "AckRequested",
"http://schemas.xmlsoap.org/ws/2005/02/rm/AckRequested", "AcksTo", "Accept", "CreateSequence",
"http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence", "CreateSequenceRefused", "CreateSequenceResponse",
"http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequenceResponse", "FaultCode", "InvalidAcknowledgement", "LastMessage",
"http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage", "LastMessageNumberExceeded", "MessageNumberRollover", "Nack", "netrm", "Offer", "r", "SequenceFault", "SequenceTerminated", "TerminateSequence",
"http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence", "UnknownSequence",
"http://schemas.microsoft.com/ws/2006/02/tx/oletx", "oletx", "OleTxTransaction", "PropagationToken",
"http://schemas.xmlsoap.org/ws/2004/10/wscoor", "wscoor", "CreateCoordinationContext", "CreateCoordinationContextResponse", "CoordinationContext", "CurrentContext", "CoordinationType", "RegistrationService", "Register", "RegisterResponse", "ProtocolIdentifier", "CoordinatorProtocolService", "ParticipantProtocolService",
"http://schemas.xmlsoap.org/ws/2004/10/wscoor/CreateCoordinationContext",
"http://schemas.xmlsoap.org/ws/2004/10/wscoor/CreateCoordinationContextResponse",
"http://schemas.xmlsoap.org/ws/2004/10/wscoor/Register",
"http://schemas.xmlsoap.org/ws/2004/10/wscoor/RegisterResponse",
"http://schemas.xmlsoap.org/ws/2004/10/wscoor/fault", "ActivationCoordinatorPortType", "RegistrationCoordinatorPortType", "InvalidState", "InvalidProtocol", "InvalidParameters", "NoActivity", "ContextRefused", "AlreadyRegistered",
"http://schemas.xmlsoap.org/ws/2004/10/wsat", "wsat",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Completion",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Durable2PC",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Volatile2PC", "Prepare", "Prepared", "ReadOnly", "Commit", "Rollback", "Committed", "Aborted", "Replay",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Commit",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Rollback",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Committed",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Aborted",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Prepare",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Prepared",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/ReadOnly",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/Replay",
"http://schemas.xmlsoap.org/ws/2004/10/wsat/fault", "CompletionCoordinatorPortType", "CompletionParticipantPortType", "CoordinatorPortType", "ParticipantPortType", "InconsistentInternalState", "mstx", "Enlistment", "protocol", "LocalTransactionId", "IsolationLevel", "IsolationFlags", "Description", "Loopback", "RegisterInfo", "ContextId", "TokenId", "AccessDenied", "InvalidPolicy", "CoordinatorRegistrationFailed", "TooManyEnlistments", "Disabled", "ActivityId",
"http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics",
"http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#Kerberosv5APREQSHA1",
"http://schemas.xmlsoap.org/ws/2002/12/policy", "FloodMessage", "LinkUtility", "Hops",
"http://schemas.microsoft.com/net/2006/05/peer/HopCount", "PeerVia",
"http://schemas.microsoft.com/net/2006/05/peer", "PeerFlooder", "PeerTo",
"http://schemas.microsoft.com/ws/2005/05/routing", "PacketRoutable",
"http://schemas.microsoft.com/ws/2005/05/addressing/none",
"http://schemas.microsoft.com/ws/2005/05/envelope/none",
"http://www.w3.org/2001/XMLSchema-instance",
"http://www.w3.org/2001/XMLSchema", "nil", "type", "char", "boolean", "byte", "unsignedByte", "short", "unsignedShort", "int", "unsignedInt", "long", "unsignedLong", "float", "double", "decimal", "dateTime", "string", "base64Binary", "anyType", "duration", "guid", "anyURI", "QName", "time", "date", "hexBinary", "gYearMonth", "gYear", "gMonthDay", "gDay", "gMonth", "integer", "positiveInteger", "negativeInteger", "nonPositiveInteger", "nonNegativeInteger", "normalizedString", "ConnectionLimitReached",
"http://schemas.xmlsoap.org/soap/envelope/", "Actor", "Faultcode", "Faultstring", "Faultactor", "Detail"
};
static BinaryFrameSupportReader ()
{
var d = new XmlDictionary ();
soap_dictionary = d;
foreach (var s in dict_strings)
d.Add (s);
}
}
}

View File

@@ -0,0 +1,220 @@
//
// BindingContextTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// 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.Collections.ObjectModel;
using System.Net.Security;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class BindingContextTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestCtorBindingNull ()
{
new BindingContext (null,
new BindingParameterCollection ());
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestCtorParametersNull ()
{
new BindingContext (new CustomBinding (), null);
}
[Test]
//[ExpectedException (typeof (ArgumentNullException))]
public void TestCtorListenUriBaseAddressNull ()
{
new BindingContext (new CustomBinding (),
new BindingParameterCollection (),
null,
"http://localhost:8080",
ListenUriMode.Unique);
}
[Test]
//[ExpectedException (typeof (ArgumentNullException))]
public void TestCtorListenUriRelativeAddressNull ()
{
new BindingContext (new CustomBinding (),
new BindingParameterCollection (),
new Uri ("http://localhost:8080"),
null,
ListenUriMode.Unique);
}
[Test]
// Now this test is mostly useless ...
public void ConsumeBindingElements ()
{
BindingContext ctx = new BindingContext (
new CustomBinding (
new TextMessageEncodingBindingElement (),
new HttpTransportBindingElement ()),
new BindingParameterCollection ());
HttpTransportBindingElement be =
new HttpTransportBindingElement ();
be.BuildChannelFactory<IRequestChannel> (ctx);
}
[Test]
[Category ("NotWorking")]
[ExpectedException (typeof (ArgumentException))]
public void DuplicateMesageEncodingBindingElementError ()
{
BindingContext ctx = new BindingContext (
new CustomBinding (
new TextMessageEncodingBindingElement (),
new HttpTransportBindingElement ()),
new BindingParameterCollection ());
TextMessageEncodingBindingElement te =
new TextMessageEncodingBindingElement ();
te.BuildChannelFactory<IRequestChannel> (ctx);
}
[Test]
public void GetInnerPropertyIsNothingToDoWithParameters ()
{
BindingParameterCollection pl =
new BindingParameterCollection ();
pl.Add (new ClientCredentials ());
BindingContext ctx =
new BindingContext (new CustomBinding (), pl);
Assert.IsNull (ctx.GetInnerProperty<ClientCredentials> ());
CustomBinding binding = new CustomBinding (new HttpTransportBindingElement ());
ctx = new BindingContext (binding, pl);
Assert.IsNull (ctx.GetInnerProperty<ClientCredentials> ());
}
[Test]
public void RemainingBindingElements ()
{
var b = new CustomBinding (
new BinaryMessageEncodingBindingElement (),
new InterceptorBindingElement2 (),
new HttpTransportBindingElement ());
Assert.AreEqual (3, new BindingContext (b, new BindingParameterCollection ()).RemainingBindingElements.Count, "#1");
Assert.IsTrue (b.CanBuildChannelFactory<IRequestChannel> (), "#2");
}
[Test]
public void RemainingBindingElements2 ()
{
var b = new CustomBinding (
new BindingElement2 (),
new InterceptorBindingElement3 (),
new BindingElement3 ());
Assert.AreEqual (3, new BindingContext (b, new BindingParameterCollection ()).RemainingBindingElements.Count, "New BindingContext element count");
Assert.IsTrue (b.CanBuildChannelFactory<IRequestChannel> (), "supports IRequestChannel?");
}
public class InterceptorBindingElement2 : BindingElement
{
public override bool CanBuildChannelFactory<TChannel> (BindingContext bc)
{
Assert.AreEqual (1, bc.Clone ().RemainingBindingElements.Count, "#i1");
Assert.IsNull (bc.GetInnerProperty<MessageEncodingBindingElement> (), "#i2");
Assert.IsNull (bc.GetInnerProperty<MessageEncoder> (), "#i3");
Assert.IsNull (bc.GetInnerProperty<MessageEncoderFactory> (), "#i4");
Assert.AreEqual (1, bc.RemainingBindingElements.Count, "#i5");
Assert.IsTrue (bc.RemainingBindingElements [0] is HttpTransportBindingElement, "#i6");
Assert.AreEqual (3, bc.Binding.CreateBindingElements ().Count, "#i7");
return base.CanBuildChannelFactory<TChannel> (bc);
}
public override BindingElement Clone ()
{
return new InterceptorBindingElement2 ();
}
public override T GetProperty<T> (BindingContext bc)
{
return null;
}
}
public class InterceptorBindingElement3 : BindingElement {
public override bool CanBuildChannelFactory<TChannel> (BindingContext bc) {
if (this is BindingElement2) {
Assert.AreEqual (2, bc.Clone ().RemainingBindingElements.Count, "1- Cloned context element count");
Assert.AreEqual (3, bc.Binding.CreateBindingElements ().Count, "1- Original binding element count");
Assert.IsTrue (bc.RemainingBindingElements [0] is InterceptorBindingElement3, "1- binding element 1 type");
Assert.IsTrue (bc.RemainingBindingElements [1] is BindingElement3, "1- binding element 2 type");
} else {
Assert.AreEqual (1, bc.Clone ().RemainingBindingElements.Count, "2- Cloned context element count");
Assert.AreEqual (3, bc.Binding.CreateBindingElements ().Count, "2- Original binding element count");
Assert.IsTrue (bc.RemainingBindingElements [0] is BindingElement3, "2- binding element 1 type");
}
return base.CanBuildChannelFactory<TChannel> (bc);
}
public override BindingElement Clone () {
return new InterceptorBindingElement3 ();
}
public override T GetProperty<T> (BindingContext bc) {
return null;
}
}
public class BindingElement2 : InterceptorBindingElement3 {
public override BindingElement Clone () {
return new BindingElement2 ();
}
public override bool CanBuildChannelFactory<TChannel> (BindingContext bc) {
return base.CanBuildChannelFactory<TChannel> (bc);
}
}
public class BindingElement3 : HttpTransportBindingElement {
public override BindingElement Clone () {
return new BindingElement3 ();
}
public override bool CanBuildChannelFactory<TChannel> (BindingContext bc) {
return base.CanBuildChannelFactory<TChannel> (bc);
}
}
}
}

View File

@@ -0,0 +1,206 @@
//
// BindingElementTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net.Security;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class BindingElementTest
{
class MyChannelFactory<TChannel>
: ChannelFactoryBase<TChannel>
{
public MyChannelFactory ()
: base ()
{
}
protected override TChannel OnCreateChannel (EndpointAddress address, Uri via)
{
throw new NotSupportedException ();
}
protected override IAsyncResult OnBeginOpen (
TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
protected override void OnEndOpen (IAsyncResult result)
{
throw new NotImplementedException ();
}
protected override void OnOpen (TimeSpan timeout)
{
throw new NotImplementedException ();
}
}
class MyChannelListener<TChannel>
: ChannelListenerBase<TChannel>
where TChannel : class, IChannel
{
public MyChannelListener ()
: base ()
{
}
public override Uri Uri {
get { throw new NotImplementedException (); }
}
protected override IAsyncResult OnBeginAcceptChannel (
TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
protected override TChannel OnAcceptChannel (TimeSpan timeout)
{
throw new NotImplementedException ();
}
protected override TChannel OnEndAcceptChannel (IAsyncResult result)
{
throw new NotImplementedException ();
}
protected override IAsyncResult OnBeginWaitForChannel (
TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
protected override bool OnEndWaitForChannel (IAsyncResult result)
{
throw new NotImplementedException ();
}
protected override bool OnWaitForChannel (TimeSpan timeout)
{
throw new NotImplementedException ();
}
protected override void OnAbort ()
{
throw new NotImplementedException ();
}
protected override IAsyncResult OnBeginClose (
TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
protected override IAsyncResult OnBeginOpen (
TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
protected override void OnEndClose (IAsyncResult result)
{
throw new NotImplementedException ();
}
protected override void OnEndOpen (IAsyncResult result)
{
throw new NotImplementedException ();
}
protected override void OnClose (TimeSpan timeout)
{
throw new NotImplementedException ();
}
protected override void OnOpen (TimeSpan timeout)
{
}
}
class MyBindingElement : BindingElement
{
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
BindingContext ctx)
{
return new MyChannelFactory<TChannel> ();
}
public override IChannelListener<TChannel> BuildChannelListener<TChannel> (
BindingContext ctx)
{
return new MyChannelListener<TChannel> ();
}
public override bool CanBuildChannelListener<TChannel> (BindingContext ctx)
{
return true;
}
public override BindingElement Clone ()
{
return new MyBindingElement ();
}
public override T GetProperty<T> (BindingContext context)
{
return null;
}
}
[Test]
[Ignore ("It is even not a test yet.")]
public void BuildChannelFactory ()
{
ServiceHost host = new ServiceHost (typeof (Foo));
host.AddServiceEndpoint (typeof (Foo),
new CustomBinding (new MyBindingElement (),
new HttpTransportBindingElement ()),
"http://localhost:8080");
host.Open ();
}
[ServiceContract]
class Foo
{
[OperationContract]
public void Whee ()
{
}
}
}
}

View File

@@ -0,0 +1,77 @@
//
// BindingTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// 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.Collections.ObjectModel;
using System.Net.Security;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class BindingTest
{
class MyBinding : Binding
{
public override string Scheme {
get { return "my"; }
}
public override BindingElementCollection CreateBindingElements ()
{
return new BindingElementCollection (
new BindingElement [] { new HttpTransportBindingElement () });
}
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void BuildChannelFactoryGeneric ()
{
// i.e. it should not reuse non-generic version of
// BuildChannelFactory().
new MyBinding ().BuildChannelFactory<IRequestChannel> ((BindingParameterCollection) null);
}
[Test]
public void BuildChannelFactoryGeneric2 ()
{
new MyBinding ().BuildChannelFactory<IRequestChannel> (
new BindingParameterCollection ());
}
[Test]
public void MessageVersionProperty ()
{
Assert.AreEqual (MessageVersion.Soap11, new BasicHttpBinding ().MessageVersion, "#1");
Assert.IsNull (new CustomBinding ().MessageVersion, "#2");
}
}
}

View File

@@ -0,0 +1,132 @@
//
// CalcSampleProxy.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
using System.Threading;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[ServiceContract]
public interface ICalc
{
[OperationContract]
int Sum (int a, int b);
[OperationContract (AsyncPattern = true)]
IAsyncResult BeginSum (int a, int b, AsyncCallback cb, object state);
int EndSum (IAsyncResult result);
}
public class CalcProxy : ClientBase<ICalc>, ICalc
{
public CalcProxy (Binding binding, EndpointAddress address)
: base (binding, address)
{
}
public int Sum (int a, int b)
{
return Channel.Sum (a, b);
}
public IAsyncResult BeginSum (int a, int b, AsyncCallback cb, object state)
{
return Channel.BeginSum (a, b, cb, state);
}
public int EndSum (IAsyncResult result)
{
return Channel.EndSum (result);
}
}
public class CalcService : ICalc
{
public int Sum (int a, int b)
{
return a + b;
}
public IAsyncResult BeginSum (int a, int b, AsyncCallback cb, object state)
{
return new CalcAsyncResult (a, b, cb, state);
}
public int EndSum (IAsyncResult result)
{
CalcAsyncResult c = (CalcAsyncResult) result;
return c.A + c.B;
}
}
class CalcAsyncResult : IAsyncResult
{
public int A, B;
AsyncCallback callback;
object state;
public CalcAsyncResult (int a, int b, AsyncCallback cb, object state)
{
A = a;
B = b;
callback = cb;
this.state = state;
}
public object AsyncState {
get { return state; }
}
public WaitHandle AsyncWaitHandle {
get { return null; }
}
public bool CompletedSynchronously {
get { return true; }
}
public bool IsCompleted {
get { return true; }
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,253 @@
//
// CommunicationObjectTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// 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.ServiceModel;
using System.ServiceModel.Channels;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
class ExtCommObj : CommunicationObject
{
public new bool Aborted, Opened, Closed, OnClosedCalled;
public ExtCommObj () : base ()
{
}
protected override TimeSpan DefaultCloseTimeout {
get { return TimeSpan.Zero; }
}
protected override TimeSpan DefaultOpenTimeout {
get { return TimeSpan.Zero; }
}
public new bool IsDisposed {
get { return base.IsDisposed; }
}
public void XFault ()
{
Fault ();
}
protected override void OnAbort ()
{
if (Aborted)
throw new Exception ("Already aborted");
Aborted = true;
}
protected override IAsyncResult OnBeginClose (
TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
protected override IAsyncResult OnBeginOpen (
TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
protected override void OnEndClose (IAsyncResult result)
{
throw new NotImplementedException ();
}
protected override void OnEndOpen (IAsyncResult result)
{
throw new NotImplementedException ();
}
protected override void OnClose (TimeSpan timeout)
{
if (Closed)
throw new Exception ("Already closed");
Closed = true;
}
protected override void OnOpen (TimeSpan timeout)
{
if (Opened)
throw new Exception ("Already opened");
Opened = true;
}
protected override void OnClosed ()
{
if (OnClosedCalled)
throw new Exception ("OnClosed() already called");
OnClosedCalled = true;
base.OnClosed ();
}
}
class ExtCommObj2 : ExtCommObj
{
public bool OnClosedCalled;
// It does not call base -> Abort() detects it as an error.
protected override void OnClosed ()
{
if (OnClosedCalled)
throw new Exception ("OnClosed() already called");
OnClosedCalled = true;
}
}
[TestFixture]
public class CommunicationObjectTest
{
[Test]
public void OpenClose ()
{
ExtCommObj obj = new ExtCommObj ();
Assert.AreEqual (CommunicationState.Created, obj.State, "#1");
obj.Open ();
Assert.AreEqual (CommunicationState.Opened, obj.State, "#2");
Assert.IsTrue (obj.Opened, "#2-2");
obj.Close ();
Assert.AreEqual (CommunicationState.Closed, obj.State, "#3");
Assert.IsTrue (obj.Closed, "#3-2");
Assert.AreEqual (true, obj.IsDisposed, "#4");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void OpenOpenFails ()
{
ExtCommObj obj = new ExtCommObj ();
obj.Open ();
obj.Open ();
}
[Test]
public void CloseAtInitialState ()
{
ExtCommObj obj = new ExtCommObj ();
obj.Close ();
Assert.IsTrue (obj.Aborted, "#1"); // OnAbort() is called.
Assert.IsFalse (obj.Closed, "#2"); // OnClose() is *not* called.
Assert.IsTrue (obj.OnClosedCalled, "#3");
}
[Test]
public void CloseAtInitialStateAsync ()
{
ExtCommObj obj = new ExtCommObj ();
obj.EndClose (obj.BeginClose (null, null)); // does not call OnBeginClose() / OnEndClose().
Assert.IsTrue (obj.Aborted, "#1");
Assert.IsFalse (obj.Closed, "#2");
Assert.IsTrue (obj.OnClosedCalled, "#3");
}
[Test]
public void CloseAtOpenedState ()
{
ExtCommObj obj = new ExtCommObj ();
obj.Open ();
obj.Close (); // Aborted() is *not* called.
Assert.IsFalse (obj.Aborted, "#1");
Assert.IsTrue (obj.Closed, "#2");
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void OpenClosedItemFails ()
{
ExtCommObj obj = new ExtCommObj ();
obj.Open ();
obj.Close ();
obj.Open ();
}
[Test]
public void Fault ()
{
ExtCommObj obj = new ExtCommObj ();
obj.XFault ();
obj = new ExtCommObj ();
obj.Open ();
obj.XFault ();
Assert.AreEqual (CommunicationState.Faulted, obj.State, "#1");
Assert.AreEqual (false, obj.IsDisposed, "#2");
}
[Test]
[ExpectedException (typeof (CommunicationObjectFaultedException))]
public void OpenFaulted ()
{
ExtCommObj obj = new ExtCommObj ();
obj.XFault ();
obj.Open ();
}
[Test]
[ExpectedException (typeof (CommunicationObjectFaultedException))]
public void CloseFaulted ()
{
ExtCommObj obj = new ExtCommObj ();
obj.Open ();
obj.XFault ();
obj.Close ();
}
[Test]
public void AbortFaulted ()
{
ExtCommObj obj = new ExtCommObj ();
obj.Open ();
obj.XFault ();
Assert.AreEqual (CommunicationState.Faulted, obj.State, "#1");
obj.Abort (); // does not raise an error
Assert.AreEqual (CommunicationState.Closed, obj.State, "#2");
Assert.IsTrue (obj.Aborted, "#3");
Assert.IsFalse (obj.Closed, "#4");
obj.Abort (); // does not raise an error!
}
[Test]
public void AbortCreated ()
{
ExtCommObj obj = new ExtCommObj ();
obj.Abort ();
Assert.IsTrue (obj.Aborted, "#1"); // OnAbort() is called.
Assert.IsFalse (obj.Closed, "#2"); // OnClose() is *not* called.
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void OnClosedImplementedWithoutCallingBase ()
{
ExtCommObj obj = new ExtCommObj2 ();
obj.Close ();
}
}
}

View File

@@ -0,0 +1,200 @@
//
// ConnectionOrientedTransportBindingElementTest.cs
//
// Author:
// Carlos Alberto Cortez <calberto.cortez@gmail.com>
//
// Copyright (C) 2010 Novell, Inc. http://www.novell.com
//
// 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.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class ConnectionOrientedTransportBindingElementTest
{
//
// We use NamedPipeTransportBindingElement to access the impl of ExportPolicy
//
[Test]
public void ExportPolicyDefault ()
{
ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement ();
IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions ();
BindingElementCollection binding_elements = conversion_context.BindingElements;
Assert.AreEqual (2, binding_assertions.Count, "#A0");
Assert.AreEqual (0, binding_elements.Count, "#A1");
// wsaw:UsingAddressing
XmlNode using_addressing_node = FindAssertion (binding_assertions, "wsaw:UsingAddressing");
Assert.AreEqual (true, using_addressing_node != null, "#B0");
Assert.AreEqual ("UsingAddressing", using_addressing_node.LocalName, "#B1");
Assert.AreEqual ("http://www.w3.org/2006/05/addressing/wsdl", using_addressing_node.NamespaceURI, "#B2");
Assert.AreEqual (String.Empty, using_addressing_node.InnerText, "#B3");
Assert.AreEqual (0, using_addressing_node.Attributes.Count, "#B4");
Assert.AreEqual (0, using_addressing_node.ChildNodes.Count, "#B5");
// msb:BinaryEncoding
XmlNode binary_encoding_node = FindAssertion (binding_assertions, "msb:BinaryEncoding");
Assert.AreEqual (true, binary_encoding_node != null, "#C0");
Assert.AreEqual ("BinaryEncoding", binary_encoding_node.LocalName, "#C1");
Assert.AreEqual ("http://schemas.microsoft.com/ws/06/2004/mspolicy/netbinary1", binary_encoding_node.NamespaceURI, "#C2");
Assert.AreEqual (String.Empty, binary_encoding_node.InnerText, "#C3");
Assert.AreEqual (0, binary_encoding_node.Attributes.Count, "#C4");
Assert.AreEqual (0, binary_encoding_node.ChildNodes.Count, "#C5");
}
//
// Non-default values
//
[Test]
public void ExportPolicy ()
{
ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement ();
binding_element.ChannelInitializationTimeout = TimeSpan.FromSeconds (3);
binding_element.ConnectionBufferSize = binding_element.ConnectionBufferSize / 2;
binding_element.HostNameComparisonMode = HostNameComparisonMode.WeakWildcard;
binding_element.ManualAddressing = !binding_element.ManualAddressing;
binding_element.MaxBufferSize = binding_element.MaxBufferSize / 2;
binding_element.MaxBufferPoolSize = binding_element.MaxBufferPoolSize / 2;
binding_element.MaxOutputDelay = TimeSpan.FromSeconds (3);
binding_element.MaxPendingAccepts = 3;
binding_element.MaxPendingConnections = 15;
binding_element.MaxReceivedMessageSize = binding_element.MaxReceivedMessageSize / 2;
binding_element.TransferMode = TransferMode.Streamed; // Causes an assertion with Streamed* values
IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions ();
BindingElementCollection binding_elements = conversion_context.BindingElements;
Assert.AreEqual (3, binding_assertions.Count, "#A0");
Assert.AreEqual (0, binding_elements.Count, "#A1");
// msf:Streamed
XmlNode streamed_node = FindAssertion (binding_assertions, "msf:Streamed");
Assert.AreEqual (true, streamed_node != null, "#B0");
Assert.AreEqual ("Streamed", streamed_node.LocalName, "#B1");
Assert.AreEqual ("http://schemas.microsoft.com/ws/2006/05/framing/policy", streamed_node.NamespaceURI, "#B2");
Assert.AreEqual (String.Empty, streamed_node.InnerText, "#B3");
Assert.AreEqual (0, streamed_node.Attributes.Count, "#B4");
Assert.AreEqual (0, streamed_node.ChildNodes.Count, "#B5");
}
// For some reason PolicyAssertionCollection.Find is not working as expected,
// so do the lookup manually.
XmlNode FindAssertion (PolicyAssertionCollection assertionCollection, string name)
{
foreach (XmlNode node in assertionCollection)
if (node.Name == name)
return node;
return null;
}
XmlNode FindAssertionByLocalName (PolicyAssertionCollection assertionCollection, string name)
{
foreach (XmlNode node in assertionCollection)
if (node.LocalName == name)
return node;
return null;
}
class MyMessageEncodingElement : MessageEncodingBindingElement {
MessageVersion version;
public MyMessageEncodingElement (MessageVersion version)
{
this.version = version;
}
public override BindingElement Clone ()
{
return new MyMessageEncodingElement (version);
}
public override MessageEncoderFactory CreateMessageEncoderFactory ()
{
throw new NotImplementedException ();
}
public override MessageVersion MessageVersion {
get {
return version;
}
set {
throw new NotImplementedException ();
}
}
}
[Test]
public void ExportPolicy_CustomEncoding_Soap12 ()
{
ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement ();
IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
conversion_context.BindingElements.Add (new MyMessageEncodingElement (MessageVersion.Soap12));
export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions ();
BindingElementCollection binding_elements = conversion_context.BindingElements;
Assert.AreEqual (0, binding_assertions.Count, "#A0");
Assert.AreEqual (1, binding_elements.Count, "#A1");
}
[Test]
public void ExportPolicy_CustomEncoding_Soap12August2004 ()
{
ConnectionOrientedTransportBindingElement binding_element = new NamedPipeTransportBindingElement ();
IPolicyExportExtension export_extension = binding_element as IPolicyExportExtension;
PolicyConversionContext conversion_context = new CustomPolicyConversionContext ();
conversion_context.BindingElements.Add (new MyMessageEncodingElement (MessageVersion.Soap12WSAddressingAugust2004));
export_extension.ExportPolicy (new WsdlExporter (), conversion_context);
PolicyAssertionCollection binding_assertions = conversion_context.GetBindingAssertions ();
BindingElementCollection binding_elements = conversion_context.BindingElements;
Assert.AreEqual (1, binding_assertions.Count, "#A0");
Assert.AreEqual (1, binding_elements.Count, "#A1");
// UsingAddressing
XmlNode using_addressing_node = FindAssertionByLocalName (binding_assertions, "UsingAddressing");
Assert.AreEqual (true, using_addressing_node != null, "#B0");
Assert.AreEqual ("UsingAddressing", using_addressing_node.LocalName, "#B1");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2004/08/addressing/policy", using_addressing_node.NamespaceURI, "#B2");
Assert.AreEqual (String.Empty, using_addressing_node.InnerText, "#B3");
Assert.AreEqual (0, using_addressing_node.Attributes.Count, "#B4");
Assert.AreEqual (0, using_addressing_node.ChildNodes.Count, "#B5");
}
}
}

View File

@@ -0,0 +1,443 @@
//
// CustomBindingTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// 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.Collections.ObjectModel;
using System.Net.Security;
using System.IdentityModel.Tokens;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
using System.Text;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class CustomBindingTest
{
[Test]
public void DefaultCtor ()
{
CustomBinding cb = new CustomBinding ();
Assert.AreEqual (0, cb.Elements.Count, "#1");
Assert.AreEqual ("CustomBinding", cb.Name, "#3");
Assert.AreEqual ("http://tempuri.org/", cb.Namespace, "#4");
Assert.AreEqual (TimeSpan.FromMinutes (1), cb.OpenTimeout, "#5");
Assert.AreEqual (TimeSpan.FromMinutes (1), cb.CloseTimeout, "#6");
Assert.AreEqual (TimeSpan.FromMinutes (1), cb.SendTimeout, "#7");
Assert.AreEqual (TimeSpan.FromMinutes (10), cb.ReceiveTimeout, "#8");
Assert.AreEqual (0, cb.CreateBindingElements ().Count, "#9");
}
class MyBinding : Binding
{
public override string Scheme { get { return "hoge"; } }
public override BindingElementCollection CreateBindingElements ()
{
throw new ApplicationException ("HEHE");
}
}
[Test]
public void CtorFromAnotherBinding ()
{
CustomBinding cb =
new CustomBinding (new WSHttpBinding ());
// Its properties become mostly copy of the original one
Assert.AreEqual (4, cb.Elements.Count, "#1");
Assert.AreEqual ("http", cb.Scheme, "#2");
Assert.AreEqual ("WSHttpBinding", cb.Name, "#3");
Assert.AreEqual ("http://tempuri.org/", cb.Namespace, "#4");
Assert.AreEqual (4, cb.CreateBindingElements ().Count, "#9");
}
class MessageVersionBindingElement : BindingElement {
public MessageVersion Version {
get;
private set;
}
public MessageVersionBindingElement (MessageVersion version)
{
this.Version = version;
}
public override BindingElement Clone ()
{
return new MessageVersionBindingElement (Version);
}
public override T GetProperty<T> (BindingContext context)
{
if (typeof (T) == typeof (MessageVersion))
return (T)(object) Version;
return null;
}
}
[Test]
public void MessageVersionProperty ()
{
Assert.IsNull (new CustomBinding ().MessageVersion, "#1");
Assert.AreEqual (MessageVersion.Soap12WSAddressing10, new CustomBinding (new HttpTransportBindingElement ()).MessageVersion, "#2");
Assert.AreEqual (MessageVersion.Soap12WSAddressing10, new CustomBinding (new TextMessageEncodingBindingElement ()).MessageVersion, "#3");
var versions = new[] {
MessageVersion.Soap11, MessageVersion.Soap11WSAddressing10,
MessageVersion.Soap11WSAddressingAugust2004,
MessageVersion.Soap12, MessageVersion.Soap12WSAddressing10,
MessageVersion.Soap12WSAddressingAugust2004
};
foreach (var version in versions) {
var binding = new CustomBinding ();
binding.Elements.Add (new MessageVersionBindingElement (version));
Assert.AreEqual (version, binding.MessageVersion, "#4:" + version);
}
}
[Test]
[ExpectedException (typeof (ApplicationException))]
public void CtorFromAnotherBindingCallsCreateBindingElement ()
{
new CustomBinding (new MyBinding ());
}
Message reqmsg, resmsg;
[Test]
public void CustomTransportDoesNotRequireMessageEncoding ()
{
ReplyHandler replier = delegate (Message msg) {
resmsg = msg;
};
RequestReceiver receiver = delegate () {
return reqmsg;
};
RequestSender sender = delegate (Message msg) {
reqmsg = msg;
CustomBinding br = new CustomBinding (
new HandlerTransportBindingElement (replier, receiver));
IChannelListener<IReplyChannel> l =
br.BuildChannelListener<IReplyChannel> (
new BindingParameterCollection ());
l.Open ();
IReplyChannel rch = l.AcceptChannel ();
rch.Open ();
Message res = Message.CreateMessage (MessageVersion.Default, "urn:succeeded");
rch.ReceiveRequest ().Reply (res);
rch.Close ();
l.Close ();
return resmsg;
};
CustomBinding bs = new CustomBinding (
new HandlerTransportBindingElement (sender));
IChannelFactory<IRequestChannel> f =
bs.BuildChannelFactory<IRequestChannel> (
new BindingParameterCollection ());
f.Open ();
IRequestChannel ch = f.CreateChannel (new EndpointAddress ("urn:dummy"));
ch.Open ();
Message result = ch.Request (Message.CreateMessage (MessageVersion.Default, "urn:request"));
}
[Test]
public void TransportBindingElementDefaultMessageVersion ()
{
Assert.AreEqual (MessageVersion.Soap12WSAddressing10, new HandlerTransportBindingElement (null).GetProperty<MessageVersion> (new BindingContext (new CustomBinding (), new BindingParameterCollection ())), "version");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
// Envelope Version 'EnvelopeNone (http://schemas.microsoft.com/ws/2005/05/envelope/none)'
// does not support adding Message Headers.
public void MessageSecurityPOX ()
{
SymmetricSecurityBindingElement sbe =
new SymmetricSecurityBindingElement ();
sbe.ProtectionTokenParameters =
new X509SecurityTokenParameters ();
RequestSender sender = delegate (Message input) {
MessageBuffer buf = input.CreateBufferedCopy (0x10000);
using (XmlWriter w = XmlWriter.Create (Console.Error)) {
buf.CreateMessage ().WriteMessage (w);
}
return buf.CreateMessage ();
};
CustomBinding binding = new CustomBinding (
sbe,
new TextMessageEncodingBindingElement (
MessageVersion.None, Encoding.UTF8),
new HandlerTransportBindingElement (sender));
EndpointAddress address = new EndpointAddress (
new Uri ("http://localhost:37564"),
new X509CertificateEndpointIdentity (new X509Certificate2 ("Test/Resources/test.pfx", "mono")));
ChannelFactory<IRequestChannel> cf =
new ChannelFactory<IRequestChannel> (binding, address);
IRequestChannel ch = cf.CreateChannel ();
/*
// neither of Endpoint, Contract nor its Operation seems
// to have applicable behaviors (except for
// ClientCredentials)
Assert.AreEqual (1, cf.Endpoint.Behaviors.Count, "EndpointBehavior");
Assert.AreEqual (0, cf.Endpoint.Contract.Behaviors.Count, "ContractBehavior");
Assert.AreEqual (1, cf.Endpoint.Contract.Operations.Count, "Operations");
OperationDescription od = cf.Endpoint.Contract.Operations [0];
Assert.AreEqual (0, od.Behaviors.Count, "OperationBehavior");
*/
ch.Open ();
try {
ch.Request (Message.CreateMessage (MessageVersion.None, "urn:myaction"));
} finally {
ch.Close ();
}
}
[Test]
[Ignore ("it's underway")]
[Category ("NotWorking")]
public void MessageSecurityManualProtection ()
{
SymmetricSecurityBindingElement sbe =
new SymmetricSecurityBindingElement ();
sbe.ProtectionTokenParameters =
new X509SecurityTokenParameters ();
RequestSender sender = delegate (Message input) {
MessageBuffer buf = input.CreateBufferedCopy (0x10000);
using (XmlWriter w = XmlWriter.Create (Console.Error)) {
buf.CreateMessage ().WriteMessage (w);
}
return buf.CreateMessage ();
};
CustomBinding binding = new CustomBinding (
sbe,
new TextMessageEncodingBindingElement (),
new HandlerTransportBindingElement (sender));
EndpointAddress address = new EndpointAddress (
new Uri ("http://localhost:37564"),
new X509CertificateEndpointIdentity (new X509Certificate2 ("Test/Resources/test.pfx", "mono")));
ChannelProtectionRequirements reqs =
new ChannelProtectionRequirements ();
reqs.OutgoingSignatureParts.AddParts (
new MessagePartSpecification (new XmlQualifiedName ("SampleValue", "urn:foo")), "urn:myaction");
BindingParameterCollection parameters =
new BindingParameterCollection ();
parameters.Add (reqs);
/*
SymmetricSecurityBindingElement innersbe =
new SymmetricSecurityBindingElement ();
innersbe.ProtectionTokenParameters =
new X509SecurityTokenParameters ();
sbe.ProtectionTokenParameters =
new SecureConversationSecurityTokenParameters (
innersbe, false, reqs);
*/
IChannelFactory<IRequestChannel> cf =
binding.BuildChannelFactory<IRequestChannel> (parameters);
cf.Open ();
IRequestChannel ch = cf.CreateChannel (address);
ch.Open ();
try {
ch.Request (Message.CreateMessage (MessageVersion.None, "urn:myaction", new SampleValue ()));
} finally {
ch.Close ();
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void CanBuildChannelListenerNoTransport ()
{
CustomBinding cb = new CustomBinding ();
BindingContext ctx = new BindingContext (
cb, new BindingParameterCollection ());
Assert.IsFalse (new TextMessageEncodingBindingElement ().CanBuildChannelListener<IReplyChannel> (ctx), "#1");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void BuildChannelListenerNoTransport ()
{
CustomBinding cb = new CustomBinding ();
BindingContext ctx = new BindingContext (
cb, new BindingParameterCollection ());
new TextMessageEncodingBindingElement ().BuildChannelListener<IReplyChannel> (ctx);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
[Category ("NotWorking")]
public void BuildChannelListenerWithDuplicateElement ()
{
CustomBinding cb = new CustomBinding (
new TextMessageEncodingBindingElement (),
new HttpTransportBindingElement ());
BindingContext ctx = new BindingContext (
cb, new BindingParameterCollection (),
new Uri ("http://localhost:37564"), String.Empty, ListenUriMode.Unique);
new TextMessageEncodingBindingElement ().BuildChannelListener<IReplyChannel> (ctx);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void BuildChannelListenerWithNoMessageVersion ()
{
// MyBindingElement overrides GetProperty<T>() without calling GetInnerProperty<T>() and returns null in this case.
// ServiceHost.Open() tries to get MessageVersion and raises an error if it cannot get any.
// HttpTransportBindingElement can actually provide one.
ServiceHost host = new ServiceHost (typeof (FooService));
host.AddServiceEndpoint (typeof (IFooService),
new CustomBinding (new MyBindingElement (false), new HttpTransportBindingElement ()),
"http://localhost:37564");
host.Open ();
}
[Test]
[ExpectedException (typeof (MyException))]
public void BuildChannelListenerWithMessageVersion ()
{
// MyBindingElement overrides GetProperty<T>() to call GetInnerProperty<T>() (default implementation).
// HttpTransportBindingElement should return Soap11.
ServiceHost host = new ServiceHost (typeof (FooService));
host.AddServiceEndpoint (typeof (IFooService),
new CustomBinding (new MyBindingElement (true), new HttpTransportBindingElement ()),
"http://localhost:37564");
host.Open ();
host.Close ();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void RelativeListenUriNoBaseAddress ()
{
// MyBindingElement overrides GetProperty<T>() to call GetInnerProperty<T>() (default implementation).
// HttpTransportBindingElement should return Soap11.
ServiceHost host = new ServiceHost (typeof (FooService));
host.AddServiceEndpoint (typeof (IFooService),
new CustomBinding (new MyBindingElement (true), new HttpTransportBindingElement ()),
"http://localhost:37564", new Uri ("foobar", UriKind.Relative));
}
[Test]
[ExpectedException (typeof (MyException))]
public void RelativeListenUriWithBaseAddress ()
{
// MyBindingElement overrides GetProperty<T>() to call GetInnerProperty<T>() (default implementation).
// HttpTransportBindingElement should return Soap11.
ServiceHost host = new ServiceHost (typeof (FooService), new Uri ("http://localhost:37564"));
host.AddServiceEndpoint (typeof (IFooService),
new CustomBinding (new MyBindingElement (true), new HttpTransportBindingElement ()),
"http://localhost:37564", new Uri ("foobar", UriKind.Relative));
host.Open ();
host.Close ();
}
[ServiceContract]
public interface IFooService
{
[OperationContract]
string Hello (string msg);
}
public class FooService : IFooService
{
public string Hello (string msg)
{
return "hello";
}
}
class MyBindingElement : BindingElement
{
public MyBindingElement (bool returnProperty)
{
return_property = returnProperty;
}
bool return_property;
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (
BindingContext ctx)
{
throw new NotImplementedException ();
}
public override IChannelListener<TChannel> BuildChannelListener<TChannel> (
BindingContext ctx)
{
throw new MyException ();
}
public override bool CanBuildChannelListener<TChannel> (BindingContext ctx)
{
return true;
}
public override BindingElement Clone ()
{
return new MyBindingElement (return_property);
}
public override T GetProperty<T> (BindingContext context)
{
return return_property ? context.GetInnerProperty<T> () : null;
}
}
public class MyException : Exception
{
}
}
[DataContract (Namespace = "urn:foo")]
class SampleValue
{
}
}

View File

@@ -0,0 +1,76 @@
//
// CustomPolicyConversionContext.cs
//
// Author:
// Carlos Alberto Cortez <calberto.cortez@gmail.com>
//
// Copyright (C) 2010 Novell, Inc. http://www.novell.com
//
// 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.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
class CustomPolicyConversionContext : PolicyConversionContext
{
PolicyAssertionCollection binding_assertions = new PolicyAssertionCollection ();
BindingElementCollection binding_elements = new BindingElementCollection ();
public CustomPolicyConversionContext ()
: base (new ServiceEndpoint (new ContractDescription ("FakeContract")))
{
}
public override PolicyAssertionCollection GetBindingAssertions ()
{
return binding_assertions;
}
public override PolicyAssertionCollection GetFaultBindingAssertions (FaultDescription fault)
{
return binding_assertions;
}
public override PolicyAssertionCollection GetMessageBindingAssertions (MessageDescription message)
{
return binding_assertions;
}
public override PolicyAssertionCollection GetOperationBindingAssertions (OperationDescription operation)
{
return binding_assertions;
}
public override BindingElementCollection BindingElements {
get {
return binding_elements;
}
}
}
}

View File

@@ -0,0 +1,174 @@
//
// DebugBindingElement.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// 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.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Xml;
using NUnit.Framework;
// This binding element class is for testing some bindings to intercept
// messages.
namespace MonoTests.System.ServiceModel.Channels
{
class DebugBindingElement : BindingElement
{
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel> (BindingContext context)
{
return new DebugChannelFactory<TChannel> (context.BuildInnerChannelFactory<TChannel> ());
}
public override BindingElement Clone ()
{
return new DebugBindingElement ();
}
public override T GetProperty<T> (BindingContext context)
{
return context.GetInnerProperty<T> ();
}
}
class DebugChannelFactory<TChannel> : ChannelFactoryBase<TChannel>
{
IChannelFactory<TChannel> inner;
public DebugChannelFactory (IChannelFactory<TChannel> inner)
{
this.inner = inner;
}
public override T GetProperty<T> ()
{
return inner.GetProperty<T> ();
}
protected override void OnOpen (TimeSpan timeout)
{
inner.Open (timeout);
}
protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotSupportedException ();
}
protected override void OnEndOpen (IAsyncResult result)
{
throw new NotSupportedException ();
}
protected override TChannel OnCreateChannel (EndpointAddress ep, Uri via)
{
if (typeof (TChannel) == typeof (IRequestChannel))
return (TChannel) (object) new DebugRequestChannel (this, (IRequestChannel) (object) inner.CreateChannel (ep, via));
throw new Exception ("huh?");
}
}
class DebugRequestChannel : RequestChannelBase
{
ChannelFactoryBase source;
IRequestChannel inner;
public DebugRequestChannel (ChannelFactoryBase source, IRequestChannel inner)
: base (source)
{
this.source = source;
this.inner = inner;
}
public override EndpointAddress RemoteAddress {
get { return inner.RemoteAddress; }
}
public override Uri Via {
get { return inner.Via; }
}
protected override void OnAbort ()
{
inner.Abort ();
}
protected override void OnOpen (TimeSpan timeout)
{
inner.Open (timeout);
}
protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotSupportedException ();
}
protected override void OnEndOpen (IAsyncResult result)
{
throw new NotSupportedException ();
}
protected override void OnClose (TimeSpan timeout)
{
inner.Close (timeout);
}
protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotSupportedException ();
}
protected override void OnEndClose (IAsyncResult result)
{
throw new NotSupportedException ();
}
public override Message Request (Message req, TimeSpan timeout)
{
XmlWriterSettings settings = new XmlWriterSettings ();
settings.Indent = true;
MessageBuffer buf = req.CreateBufferedCopy (0x10000);
using (XmlWriter w = XmlWriter.Create (Console.Error, settings)) {
buf.CreateMessage ().WriteMessage (w);
}
Console.Error.WriteLine ("******************** Debug Request() ********************");
Console.Error.Flush ();
return inner.Request (buf.CreateMessage (), timeout);
}
public override IAsyncResult BeginRequest (Message req, TimeSpan timeout, AsyncCallback callback, object state)
{
throw new NotSupportedException ();
}
public override Message EndRequest (IAsyncResult result)
{
throw new NotSupportedException ();
}
}
}

View File

@@ -0,0 +1,52 @@
#if USE_DEPRECATED
// EmptyFaultException does not exist anymore
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class EmptyFaultExceptionTest
{
[Test]
public void TestDefaults ()
{
EmptyFaultException e = new EmptyFaultException ();
Assert.AreEqual (MessageFault.DefaultAction, e.Action);
Assert.IsTrue (e.Code.IsSenderFault);
Assert.IsNull (e.Code.SubCode);
Assert.AreEqual ("Unspecified ServiceModel Fault.", e.Reason.GetMatchingTranslation ().Text);
}
[Test]
[Ignore ("bad English-oriented test")]
public void TestToString ()
{
EmptyFaultException e = new EmptyFaultException ();
Assert.AreEqual (
String.Format ("{0}: {1} (Fault Detail is equal to null).", e.GetType (), e.Message),
e.ToString ());
}
bool AreEqual (MessageFault a, MessageFault b)
{
return a.Actor == b.Actor && a.Code == b.Code && a.HasDetail == b.HasDetail && a.Node == b.Node && a.Reason == b.Reason;
}
[Test]
public void TestCreateMessageFault ()
{
EmptyFaultException e = new EmptyFaultException ();
Assert.IsTrue (
AreEqual (MessageFault.CreateFault (e.Code, e.Reason), e.CreateMessageFault ()));
}
}
}
#endif

View File

@@ -0,0 +1,68 @@
//
// MessageVersionTest.cs
//
// Author:
// Duncan Mak <duncan@ximian.com>
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005 Novell, Inc. http://www.novell.com
//
// 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.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class EnvelopeVersionTest
{
[Test]
public void GetUltimateDestinationActorValuesTest ()
{
// SOAP 1.1
Assert.AreEqual (2, EnvelopeVersion.Soap11.GetUltimateDestinationActorValues ().Length, "#1");
Assert.AreEqual (String.Empty, EnvelopeVersion.Soap11.GetUltimateDestinationActorValues () [0], "#2");
Assert.AreEqual ("http://schemas.xmlsoap.org/soap/actor/next", EnvelopeVersion.Soap11.GetUltimateDestinationActorValues () [1], "#3");
// SOAP 1.2
Assert.AreEqual (3, EnvelopeVersion.Soap12.GetUltimateDestinationActorValues ().Length, "#4");
Assert.AreEqual (String.Empty,
EnvelopeVersion.Soap12.GetUltimateDestinationActorValues () [0], "#5");
Assert.AreEqual ("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver",
EnvelopeVersion.Soap12.GetUltimateDestinationActorValues () [1], "#6");
Assert.AreEqual ("http://www.w3.org/2003/05/soap-envelope/role/next",
EnvelopeVersion.Soap12.GetUltimateDestinationActorValues () [2], "#7");
}
[Test]
public void Equality ()
{
Assert.AreEqual (EnvelopeVersion.Soap12, MessageVersion.Default.Envelope, "#1");
Assert.IsTrue (EnvelopeVersion.Soap12 == MessageVersion.Default.Envelope, "#2");
Assert.IsTrue (Object.ReferenceEquals (EnvelopeVersion.Soap12, MessageVersion.Default.Envelope), "#3");
}
}
}

View File

@@ -0,0 +1,165 @@
//
// FaultConverterTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// 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.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class FaultConverterTest
{
static readonly FaultConverter s11 = FaultConverter.GetDefaultFaultConverter (MessageVersion.Soap11WSAddressing10);
static readonly FaultConverter s12 = FaultConverter.GetDefaultFaultConverter (MessageVersion.Soap12WSAddressing10);
static readonly FaultConverter none = FaultConverter.GetDefaultFaultConverter (MessageVersion.None);
XmlWriterSettings GetWriterSettings ()
{
XmlWriterSettings s = new XmlWriterSettings ();
s.OmitXmlDeclaration = true;
return s;
}
[Test]
public void TryCreateFaultMessageDefault ()
{
Message msg;
Assert.IsFalse (s12.TryCreateFaultMessage (new Exception ("error happened"), out msg), "#1-1");
Assert.IsFalse (s12.TryCreateFaultMessage (new FaultException ("fault happened", FaultCode.CreateSenderFaultCode (new FaultCode ("IAmBroken"))), out msg), "#1-2");
Assert.IsFalse (s12.TryCreateFaultMessage (new FaultException<string> ("fault happened."), out msg), "#1-3");
Assert.IsTrue (s12.TryCreateFaultMessage (new ActionNotSupportedException (), out msg), "#1-4");
Assert.IsTrue (msg.IsFault, "#1-5");
Assert.AreEqual ("http://www.w3.org/2005/08/addressing/fault", msg.Headers.Action, "#1-6");
var f = MessageFault.CreateFault (msg, 1000);
Assert.AreEqual ("Sender", f.Code.Name, "#1-7");
Assert.AreEqual ("http://www.w3.org/2003/05/soap-envelope", f.Code.Namespace, "#1-8");
Assert.AreEqual ("ActionNotSupported", f.Code.SubCode.Name, "#1-9");
Assert.AreEqual ("http://www.w3.org/2005/08/addressing", f.Code.SubCode.Namespace, "#1-10");
Assert.IsFalse (s11.TryCreateFaultMessage (new Exception ("error happened"), out msg), "#2-1");
Assert.IsFalse (s11.TryCreateFaultMessage (new FaultException ("fault happened", FaultCode.CreateSenderFaultCode (new FaultCode ("IAmBroken"))), out msg), "#2-2");
Assert.IsFalse (s11.TryCreateFaultMessage (new FaultException<string> ("fault happened."), out msg), "#2-3");
Assert.IsTrue (s11.TryCreateFaultMessage (new ActionNotSupportedException (), out msg), "#2-4");
Assert.IsTrue (msg.IsFault, "#2-5");
Assert.AreEqual ("http://www.w3.org/2005/08/addressing/fault", msg.Headers.Action, "#2-6");
f = MessageFault.CreateFault (msg, 1000);
Assert.AreEqual ("ActionNotSupported", f.Code.Name, "#2-7");
Assert.AreEqual ("http://www.w3.org/2005/08/addressing", f.Code.Namespace, "#2-8");
Assert.IsFalse (none.TryCreateFaultMessage (new Exception ("error happened"), out msg), "#3-1");
Assert.IsFalse (none.TryCreateFaultMessage (new FaultException ("fault happened", FaultCode.CreateSenderFaultCode (new FaultCode ("IAmBroken"))), out msg), "#3-2");
Assert.IsFalse (none.TryCreateFaultMessage (new FaultException<string> ("fault happened."), out msg), "#3-3");
Assert.IsFalse (none.TryCreateFaultMessage (new ActionNotSupportedException (), out msg), "#3-4");
Assert.IsFalse (none.TryCreateFaultMessage (new EndpointNotFoundException (), out msg), "#3-5");
}
string xml1 = @"
<s:Envelope xmlns:a='http://www.w3.org/2005/08/addressing' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>
<s:Header>
<a:Action s:mustUnderstand='1'>http://www.w3.org/2005/08/addressing/fault</a:Action>
</s:Header>
<s:Body>
<s:Fault>
<faultcode>a:ActionNotSupported</faultcode>
<faultstring xml:lang='en-US'>some error</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>";
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TryCreateExceptionMessageNullDefault ()
{
var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
var mf = MessageFault.CreateFault (msg, 1000);
Exception ex;
s11.TryCreateException (null, mf, out ex);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TryCreateExceptionFaultNullDefault ()
{
var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
Exception ex;
s11.TryCreateException (msg, null, out ex);
}
[Test]
public void TryCreateExceptionDefault ()
{
var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
var mf = MessageFault.CreateFault (msg, 1000);
msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
Exception ex;
Assert.IsTrue (s11.TryCreateException (msg, mf, out ex), "#1");
// foobar -> false
Assert.IsFalse (s11.TryCreateException (msg, MessageFault.CreateFault (new FaultCode ("foobar"), new FaultReason ("foobar reason")), out ex), "#2");
// SOAP 1.1 ActionNotSupported -> true
Assert.IsTrue (s11.TryCreateException (msg, MessageFault.CreateFault (new FaultCode ("ActionNotSupported", Constants.WsaNamespace), new FaultReason ("foobar reason")), out ex), "#3");
Assert.IsTrue (ex is ActionNotSupportedException, "#3-2");
Assert.IsTrue (ex.Message.IndexOf ("foobar") >= 0, "#3-3");
// SOAP 1.1 Sender/ActionNotSupported -> false
mf = MessageFault.CreateFault (new FaultCode ("Sender", new FaultCode ("ActionNotSupported", Constants.WsaNamespace)), new FaultReason ("foobar reason"));
Assert.IsFalse (s11.TryCreateException (msg, mf, out ex), "#4");
// SOAP 1.2 ActionNotSupported -> false
mf = MessageFault.CreateFault (new FaultCode ("ActionNotSupported", Constants.WsaNamespace), new FaultReason ("foobar reason"));
Assert.IsFalse (s12.TryCreateException (msg, mf, out ex), "#5");
// SOAP 1.2 Sender/ActionNotSupported -> true
mf = MessageFault.CreateFault (new FaultCode ("Sender", new FaultCode ("ActionNotSupported", Constants.WsaNamespace)), new FaultReason ("foobar reason"));
Assert.IsTrue (s12.TryCreateException (msg, mf, out ex), "#6");
Assert.IsTrue (ex is ActionNotSupportedException, "#6-2");
Assert.IsTrue (ex.Message.IndexOf ("foobar") >= 0, "#6-3");
}
[Test]
public void TryCreateException2Default ()
{
// test buffered copy (which used to fail)
var msg = Message.CreateMessage (XmlReader.Create (new StringReader (xml1)), 0x1000, MessageVersion.Soap11WSAddressing10);
var mb = msg.CreateBufferedCopy (1000);
var mf = MessageFault.CreateFault (mb.CreateMessage (), 1000);
Exception ex;
Assert.IsTrue (s11.TryCreateException (mb.CreateMessage (), mf, out ex), "#7");
}
}
}

View File

@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class FaultExceptionTest
{
[Test]
public void TestDefaults ()
{
FaultException<int> e = new FaultException<int> (0);
Assert.AreEqual (0, e.Detail, "#1");
Assert.IsNull (e.Action, "#2");
}
[Test]
public void TestMessage ()
{
FaultException<int> e = new FaultException<int> (0);
Assert.AreEqual (e.Message, e.Reason.GetMatchingTranslation ().Text);
}
[Test]
public void TestCode ()
{
// default Code is a SenderFault with a null SubCode
FaultException<int> e = new FaultException<int> (0);
Assert.IsTrue (e.Code.IsSenderFault);
Assert.IsNull (e.Code.SubCode);
}
[Test]
public void TestAction ()
{
FaultException<int> e = new FaultException<int> (0);
Assert.IsNull (e.Action);
}
static void AreMessageFaultEqual (MessageFault a, MessageFault b, string label)
{
Assert.AreEqual (a.Actor, b.Actor, label + ".Actor");
Assert.AreEqual (a.Code, b.Code, label + ".Code");
Assert.AreEqual (a.HasDetail, b.HasDetail, label + ".HasDetail");
Assert.AreEqual (a.Node, b.Node, label + ".Node");
Assert.AreEqual (a.Reason, b.Reason, label + ".Reason");
}
[Test]
public void TestCreateMessageFault ()
{
FaultException<int> e = new FaultException<int> (0); Assert.IsFalse (
(object) MessageFault.CreateFault (e.Code, e.Reason, e.Detail)
== e.CreateMessageFault (), "#1");
AreMessageFaultEqual (
MessageFault.CreateFault (e.Code, e.Reason, e.Detail),
e.CreateMessageFault (), "#2");
}
[Test]
[Ignore ("this test is old")]
public void TestGetObjectData ()
{
FaultException<int> e = new FaultException<int> (0);
if (true) {
XmlWriterSettings s = new XmlWriterSettings ();
s.Indent = true;
s.ConformanceLevel = ConformanceLevel.Fragment;
XmlWriter w = XmlWriter.Create (TextWriter.Null, s);
XmlObjectSerializer formatter = new DataContractSerializer (typeof (int));
formatter.WriteObject (w, e);
w.Close ();
}
}
[Test]
[Ignore ("This test premises English.")]
public void TestToString ()
{
FaultException<int> e = new FaultException<int> (0);
Assert.AreEqual (
String.Format ("{0}: {1} (Fault Detail is equal to {2}).", e.GetType (), e.Message, e.Detail),
e.ToString ());
}
}
}

View File

@@ -0,0 +1,55 @@
//
// HandlerBodyWriter.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// 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.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Xml;
namespace MonoTests.System.ServiceModel.Channels
{
public delegate void BodyContentsWriter (XmlDictionaryWriter writer);
public class HandlerBodyWriter : BodyWriter
{
BodyContentsWriter handler;
public HandlerBodyWriter (BodyContentsWriter handler)
: base (true)
{
this.handler = handler;
}
protected override void OnWriteBodyContents (XmlDictionaryWriter writer)
{
handler (writer);
}
}
}

Some files were not shown because too many files have changed in this diff Show More