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,328 @@
//
// BasicHttpBindingTest.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;
using System.Net.Security;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
using NUnit.Framework;
using System.ServiceModel.Configuration;
using System.Configuration;
using System.Text;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class BasicHttpBindingTest
{
[Test]
public void DefaultValues ()
{
BasicHttpBinding b = new BasicHttpBinding ();
DefaultValues (b);
// BasicHttpSecurity
BasicHttpSecurity sec = b.Security;
Assert.IsNotNull (sec, "#2-1");
Assert.AreEqual (BasicHttpSecurityMode.None, sec.Mode, "#2-2");
BasicHttpMessageSecurity msg = sec.Message;
Assert.IsNotNull (msg, "#2-3-1");
Assert.AreEqual (SecurityAlgorithmSuite.Default, msg.AlgorithmSuite, "#2-3-2");
Assert.AreEqual (BasicHttpMessageCredentialType.UserName, msg.ClientCredentialType, "#2-3-3");
HttpTransportSecurity trans = sec.Transport;
Assert.IsNotNull (trans, "#2-4-1");
Assert.AreEqual (HttpClientCredentialType.None, trans.ClientCredentialType, "#2-4-2");
Assert.AreEqual (HttpProxyCredentialType.None, trans.ProxyCredentialType, "#2-4-3");
Assert.AreEqual ("", trans.Realm, "#2-4-4");
// Binding elements
BindingElementCollection bec = b.CreateBindingElements ();
Assert.AreEqual (2, bec.Count, "#5-1");
Assert.AreEqual (typeof (TextMessageEncodingBindingElement),
bec [0].GetType (), "#5-2");
Assert.AreEqual (typeof (HttpTransportBindingElement),
bec [1].GetType (), "#5-3");
}
[Test]
public void DefaultValueSecurityModeMessage ()
{
BasicHttpBinding b = new BasicHttpBinding (BasicHttpSecurityMode.Message);
b.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
DefaultValues (b);
// BasicHttpSecurity
BasicHttpSecurity sec = b.Security;
Assert.IsNotNull (sec, "#2-1");
Assert.AreEqual (BasicHttpSecurityMode.Message, sec.Mode, "#2-2");
BasicHttpMessageSecurity msg = sec.Message;
Assert.IsNotNull (msg, "#2-3-1");
Assert.AreEqual (SecurityAlgorithmSuite.Default, msg.AlgorithmSuite, "#2-3-2");
Assert.AreEqual (BasicHttpMessageCredentialType.Certificate, msg.ClientCredentialType, "#2-3-3");
HttpTransportSecurity trans = sec.Transport;
Assert.IsNotNull (trans, "#2-4-1");
Assert.AreEqual (HttpClientCredentialType.None, trans.ClientCredentialType, "#2-4-2");
Assert.AreEqual (HttpProxyCredentialType.None, trans.ProxyCredentialType, "#2-4-3");
Assert.AreEqual ("", trans.Realm, "#2-4-4");
// Binding elements
BindingElementCollection bec = b.CreateBindingElements ();
Assert.AreEqual (3, bec.Count, "#5-1");
Assert.AreEqual (typeof (AsymmetricSecurityBindingElement),
bec [0].GetType (), "#5-2");
Assert.AreEqual (typeof (TextMessageEncodingBindingElement),
bec [1].GetType (), "#5-3");
Assert.AreEqual (typeof (HttpTransportBindingElement),
bec [2].GetType (), "#5-4");
}
void DefaultValues (BasicHttpBinding b)
{
Assert.AreEqual (false, b.BypassProxyOnLocal, "#1");
Assert.AreEqual (HostNameComparisonMode.StrongWildcard,
b.HostNameComparisonMode, "#2");
Assert.AreEqual (0x80000, b.MaxBufferPoolSize, "#3");
Assert.AreEqual (0x10000, b.MaxBufferSize, "#4");
Assert.AreEqual (0x10000, b.MaxReceivedMessageSize, "#5");
Assert.AreEqual (WSMessageEncoding.Text, b.MessageEncoding, "#6");
Assert.IsNull (b.ProxyAddress, "#7");
// FIXME: test b.ReaderQuotas
Assert.AreEqual ("http", b.Scheme, "#8");
Assert.AreEqual (EnvelopeVersion.Soap11, b.EnvelopeVersion, "#9");
Assert.AreEqual (65001, b.TextEncoding.CodePage, "#10"); // utf-8
Assert.AreEqual (TransferMode.Buffered, b.TransferMode, "#11");
Assert.AreEqual (true, b.UseDefaultWebProxy, "#12");
/*
// Interfaces
IBindingDeliveryCapabilities ib = (IBindingDeliveryCapabilities ) b;
Assert.AreEqual (false, ib.AssuresOrderedDelivery, "#2-1");
Assert.AreEqual (false, ib.QueuedDelivery, "#2-3");
IBindingMulticastCapabilities imc = (IBindingMulticastCapabilities) b;
Assert.AreEqual (false, imc.IsMulticast, "#2.2-1");
IBindingRuntimePreferences ir =
(IBindingRuntimePreferences) b;
Assert.AreEqual (false, ir.ReceiveSynchronously, "#3-1");
ISecurityCapabilities ic = b as ISecurityCapabilities;
Assert.AreEqual (ProtectionLevel.None,
ic.SupportedRequestProtectionLevel, "#4-1");
Assert.AreEqual (ProtectionLevel.None,
ic.SupportedResponseProtectionLevel, "#4-2");
Assert.AreEqual (false, ic.SupportsClientAuthentication, "#4-3");
Assert.AreEqual (false, ic.SupportsClientWindowsIdentity, "#4-4");
Assert.AreEqual (false, ic.SupportsServerAuthentication, "#4-5");
*/
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void DefaultValueSecurityModeMessageError ()
{
BasicHttpBinding b = new BasicHttpBinding (BasicHttpSecurityMode.Message);
// "BasicHttp binding requires that BasicHttpBinding.Security.Message.ClientCredentialType be equivalent to the BasicHttpMessageCredentialType.Certificate credential type for secure messages. Select Transport or TransportWithMessageCredential security for UserName credentials."
b.CreateBindingElements ();
}
[Test]
public void MessageEncoding ()
{
BasicHttpBinding b = new BasicHttpBinding ();
foreach (BindingElement be in b.CreateBindingElements ()) {
MessageEncodingBindingElement mbe =
be as MessageEncodingBindingElement;
if (mbe != null) {
MessageEncoderFactory f = mbe.CreateMessageEncoderFactory ();
MessageEncoder e = f.Encoder;
Assert.AreEqual (typeof (TextMessageEncodingBindingElement), mbe.GetType (), "#1-1");
Assert.AreEqual (MessageVersion.Soap11, f.MessageVersion, "#2-1");
Assert.AreEqual ("text/xml; charset=utf-8", e.ContentType, "#3-1");
Assert.AreEqual ("text/xml", e.MediaType, "#3-2");
return;
}
}
Assert.Fail ("No message encodiing binding element.");
}
[Test]
public void ApplyConfiguration ()
{
BasicHttpBinding b = CreateBindingFromConfig ();
Assert.AreEqual (true, b.AllowCookies, "#1");
Assert.AreEqual (true, b.BypassProxyOnLocal, "#2");
Assert.AreEqual (HostNameComparisonMode.Exact, b.HostNameComparisonMode, "#3");
Assert.AreEqual (262144, b.MaxBufferPoolSize, "#4");
Assert.AreEqual (32768, b.MaxBufferSize, "#5");
Assert.AreEqual (32768, b.MaxReceivedMessageSize, "#6");
Assert.AreEqual ("proxy", b.ProxyAddress.ToString (), "#7");
Assert.AreEqual (Encoding.Unicode, b.TextEncoding, "#7");
Assert.AreEqual (TransferMode.Streamed, b.TransferMode, "#7");
}
[Test]
public void CreateBindingElements ()
{
BasicHttpBinding b = CreateBindingFromConfig ();
// Binding elements
BindingElementCollection bec = b.CreateBindingElements ();
Assert.AreEqual (2, bec.Count, "#1");
Assert.AreEqual (typeof (TextMessageEncodingBindingElement),
bec [0].GetType (), "#2");
Assert.AreEqual (typeof (HttpTransportBindingElement),
bec [1].GetType (), "#3");
}
[Test]
public void Elements_MessageEncodingBindingElement ()
{
BasicHttpBinding b = CreateBindingFromConfig ();
BindingElementCollection bec = b.CreateBindingElements ();
TextMessageEncodingBindingElement m =
(TextMessageEncodingBindingElement) bec [0];
Assert.AreEqual (64, m.MaxReadPoolSize, "#1");
Assert.AreEqual (16, m.MaxWritePoolSize, "#2");
Assert.AreEqual (4096, m.ReaderQuotas.MaxArrayLength, "#3");
Assert.AreEqual (8192, m.ReaderQuotas.MaxBytesPerRead, "#4");
Assert.AreEqual (64, m.ReaderQuotas.MaxDepth, "#5");
Assert.AreEqual (8192, m.ReaderQuotas.MaxNameTableCharCount, "#6");
Assert.AreEqual (16384, m.ReaderQuotas.MaxStringContentLength, "#7");
Assert.AreEqual (Encoding.Unicode, m.WriteEncoding, "#8");
}
[Test]
public void Elements_TransportBindingElement ()
{
BasicHttpBinding b = CreateBindingFromConfig ();
BindingElementCollection bec = b.CreateBindingElements ();
HttpTransportBindingElement t =
(HttpTransportBindingElement) bec [1];
Assert.AreEqual (true, t.AllowCookies, "#1");
Assert.AreEqual (AuthenticationSchemes.Anonymous, t.AuthenticationScheme, "#2");
Assert.AreEqual (true, t.BypassProxyOnLocal, "#3");
Assert.AreEqual (HostNameComparisonMode.Exact, t.HostNameComparisonMode, "#4");
Assert.AreEqual (true, t.KeepAliveEnabled, "#5");
Assert.AreEqual (false, t.ManualAddressing, "#6");
Assert.AreEqual (262144, t.MaxBufferPoolSize, "#7");
Assert.AreEqual (32768, t.MaxBufferSize, "#8");
Assert.AreEqual (32768, t.MaxReceivedMessageSize, "#9");
Assert.AreEqual ("proxy", t.ProxyAddress.ToString (), "#10");
Assert.AreEqual (AuthenticationSchemes.Anonymous, t.ProxyAuthenticationScheme, "#11");
Assert.AreEqual ("", t.Realm, "#12");
Assert.AreEqual ("http", t.Scheme, "#13");
Assert.AreEqual (TransferMode.Streamed, t.TransferMode, "#14");
Assert.AreEqual (false, t.UnsafeConnectionNtlmAuthentication, "#15");
Assert.AreEqual (false, t.UseDefaultWebProxy, "#16");
}
[Test]
public void SecurityMode ()
{
// hmm, against my expectation, those modes does not give Http(s)TransportBindingElement property differences..
var modes = new HttpClientCredentialType [] {HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate};
foreach (var m in modes) {
var b = new BasicHttpBinding ();
b.Security.Mode = BasicHttpSecurityMode.Transport;
b.Security.Transport.ClientCredentialType = m;
var bec = b.CreateBindingElements ();
Assert.AreEqual (2, bec.Count, "#1." + m);
Assert.IsTrue (bec [1] is HttpsTransportBindingElement, "#2." + m);
var tbe = (HttpsTransportBindingElement) bec [1];
if (m == HttpClientCredentialType.Certificate)
Assert.IsTrue (tbe.RequireClientCertificate, "#3." + m);
else
Assert.IsFalse (tbe.RequireClientCertificate, "#3." + m);
}
}
[Test]
public void SecurityMode2 ()
{
var modes = new HttpClientCredentialType [] {HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate};
foreach (var m in modes) {
var b = new BasicHttpBinding ();
b.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; // gives WS-Security message security.
b.Security.Transport.ClientCredentialType = m;
var bec = b.CreateBindingElements ();
Assert.AreEqual (3, bec.Count, "#1." + m);
Assert.IsTrue (bec [0] is TransportSecurityBindingElement, "#2." + m);
Assert.IsTrue (bec [2] is HttpsTransportBindingElement, "#3." + m);
var tbe = (HttpsTransportBindingElement) bec [2];
Assert.IsFalse (tbe.RequireClientCertificate, "#4." + m);
}
}
[Test]
public void SecurityMode3 ()
{
var modes = new HttpClientCredentialType [] {HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows};
var auths = new AuthenticationSchemes [] { AuthenticationSchemes.Anonymous, AuthenticationSchemes.Basic, AuthenticationSchemes.Digest, AuthenticationSchemes.Ntlm, AuthenticationSchemes.Negotiate }; // specifically, none->anonymous, and windows->negotiate
for (int i = 0; i < modes.Length; i++) {
var m = modes [i];
var b = new BasicHttpBinding ();
b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; // gives WS-Security message security.
b.Security.Transport.ClientCredentialType = m;
var bec = b.CreateBindingElements ();
Assert.AreEqual (2, bec.Count, "#1." + m);
Assert.IsTrue (bec [1] is HttpTransportBindingElement, "#2." + m);
var tbe = (HttpTransportBindingElement) bec [1];
Assert.AreEqual (auths [i], tbe.AuthenticationScheme, "#3." + m);
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void SecurityMode4 ()
{
var b = new BasicHttpBinding ();
b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; // gives WS-Security message security.
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var bec = b.CreateBindingElements ();
}
private BasicHttpBinding CreateBindingFromConfig ()
{
ServiceModelSectionGroup config = (ServiceModelSectionGroup) ConfigurationManager.OpenExeConfiguration ("Test/config/basicHttpBinding").GetSectionGroup ("system.serviceModel");
BindingsSection section = (BindingsSection) config.Bindings;
BasicHttpBindingElement el = section.BasicHttpBinding.Bindings ["BasicHttpBinding2_Service"];
BasicHttpBinding b = new BasicHttpBinding ();
el.ApplyConfiguration (b);
return b;
}
}
}

View File

@@ -0,0 +1,365 @@
//
// CallbackBehaviorAttributeTest.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.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Transactions;
using System.Threading;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class CallbackBehaviorAttributeTest
{
[Test]
public void DefaultValues ()
{
var c = new CallbackBehaviorAttribute ();
Assert.IsTrue (c.AutomaticSessionShutdown, "#1");
Assert.AreEqual (ConcurrencyMode.Single, c.ConcurrencyMode, "#2");
Assert.IsFalse (c.IgnoreExtensionDataObject, "#3");
Assert.IsFalse (c.IncludeExceptionDetailInFaults, "#4");
Assert.AreEqual (0x10000, c.MaxItemsInObjectGraph, "#5");
Assert.AreEqual (IsolationLevel.Unspecified, c.TransactionIsolationLevel, "#6");
Assert.IsNull (c.TransactionTimeout, "#7");
Assert.IsTrue (c.UseSynchronizationContext, "#8");
Assert.IsTrue (c.ValidateMustUnderstand, "#9");
}
[Test]
public void AddBindingParameters ()
{
IEndpointBehavior eb = new CallbackBehaviorAttribute ();
var cd = ContractDescription.GetContract (typeof (IFoo));
var se = new ServiceEndpoint (cd);
Assert.AreEqual (0, se.Behaviors.Count, "#1");
var pc = new BindingParameterCollection ();
eb.AddBindingParameters (se, pc);
Assert.AreEqual (0, pc.Count, "#2");
Assert.AreEqual (0, se.Behaviors.Count, "#3");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ApplyDispatchBehavior ()
{
// It cannot be applied to service endpoint dispatcher.
IEndpointBehavior eb = new CallbackBehaviorAttribute () { ConcurrencyMode = ConcurrencyMode.Multiple, ValidateMustUnderstand = false };
var cd = ContractDescription.GetContract (typeof (IFoo));
var se = new ServiceEndpoint (cd);
var ed = new EndpointDispatcher (new EndpointAddress ("http://localhost:37564"), "IFoo", "urn:foo");
eb.ApplyDispatchBehavior (se, ed);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ApplyClientBehaviorNonDuplex ()
{
// It must be applied to duplex callback runtime
IEndpointBehavior eb = new CallbackBehaviorAttribute () { ConcurrencyMode = ConcurrencyMode.Multiple, ValidateMustUnderstand = false };
var cd = ContractDescription.GetContract (typeof (IFoo));
var se = new ServiceEndpoint (cd);
var ed = new EndpointDispatcher (new EndpointAddress ("http://localhost:37564"), "IFoo", "urn:foo");
var cr = ed.DispatchRuntime.CallbackClientRuntime;
eb.ApplyClientBehavior (se, cr);
}
/* There is no way that I can create ClientRuntime instance ...
[Test]
public void ApplyClientBehavior ()
{
IEndpointBehavior eb = new CallbackBehaviorAttribute () { ConcurrencyMode = ConcurrencyMode.Multiple, ValidateMustUnderstand = false };
var cd = ContractDescription.GetContract (typeof (IDuplexFoo));
var se = new ServiceEndpoint (cd);
var ed = new EndpointDispatcher (new EndpointAddress ("http://localhost:37564"), "IDuplexFoo", "urn:foo");
var cr = ed.DispatchRuntime.CallbackClientRuntime;
eb.ApplyClientBehavior (se, cr);
Assert.IsFalse (cr.ValidateMustUnderstand, "#2.1");
//Assert.IsFalse (cr.CallbackDispatchRuntime.ValidateMustUnderstand, "#2.2");
Assert.AreEqual (1, se.Behaviors.Count, "#3");
}
*/
[ServiceContract]
public interface IFoo
{
[OperationContract]
string Join (string s1, string s2);
}
[ServiceContract (CallbackContract = typeof (IFoo))]
public interface IDuplexFoo
{
[OperationContract]
void Block (string s);
}
#region "bug #567672"
[Test]
[Category ("NotWorking")]
public void CallbackExample1 ()
{
//Start service and use net.tcp binding
ServiceHost eventServiceHost = new ServiceHost (typeof (GreetingsService));
NetTcpBinding tcpBindingpublish = new NetTcpBinding ();
tcpBindingpublish.Security.Mode = SecurityMode.None;
eventServiceHost.AddServiceEndpoint (typeof (IGreetings), tcpBindingpublish, "net.tcp://localhost:8000/GreetingsService");
var cd = eventServiceHost.Description.Endpoints [0].Contract;
Assert.AreEqual (2, cd.Operations.Count, "Operations.Count");
var send = cd.Operations.FirstOrDefault (od => od.Name == "SendMessage");
var show = cd.Operations.FirstOrDefault (od => od.Name == "ShowMessage");
Assert.IsNotNull (send, "OD:SendMessage");
Assert.IsNotNull (show, "OD:ShowMessage");
foreach (var md in send.Messages) {
if (md.Direction == MessageDirection.Input)
Assert.AreEqual ("http://tempuri.org/IGreetings/SendMessage", md.Action, "MD:SendMessage");
else
Assert.AreEqual ("http://tempuri.org/IGreetings/SendMessageResponse", md.Action, "MD:SendMessage");
}
foreach (var md in show.Messages) {
if (md.Direction == MessageDirection.Output)
Assert.AreEqual ("http://tempuri.org/IGreetings/ShowMessage", md.Action, "MD:ShowMessage");
else
Assert.AreEqual ("http://tempuri.org/IGreetings/ShowMessageResponse", md.Action, "MD:ShowMessage");
}
eventServiceHost.Open ();
var chd = (ChannelDispatcher) eventServiceHost.ChannelDispatchers [0];
Assert.IsNotNull (chd, "ChannelDispatcher");
Assert.AreEqual (1, chd.Endpoints.Count, "ChannelDispatcher.Endpoints.Count");
var ed = chd.Endpoints [0];
var cr = ed.DispatchRuntime.CallbackClientRuntime;
Assert.IsNotNull (cr, "CR");
Assert.AreEqual (1, cr.Operations.Count, "CR.Operations.Count");
Assert.AreEqual ("http://tempuri.org/IGreetings/ShowMessage", cr.Operations [0].Action, "ClientOperation.Action");
//Create client proxy
NetTcpBinding clientBinding = new NetTcpBinding ();
clientBinding.Security.Mode = SecurityMode.None;
EndpointAddress ep = new EndpointAddress ("net.tcp://localhost:8000/GreetingsService");
ClientCallback cb = new ClientCallback ();
IGreetings proxy = DuplexChannelFactory<IGreetings>.CreateChannel (new InstanceContext (cb), clientBinding, ep);
//Call service
proxy.SendMessage ();
//Wait for callback - sort of hack, but better than using wait handle to possibly block tests.
Thread.Sleep (2000);
//Cleanup
eventServiceHost.Close ();
Assert.IsTrue (CallbackSent, "#1");
Assert.IsTrue (CallbackReceived, "#2");
}
[Test]
[Category ("NotWorking")]
public void CallbackExample2 ()
{
//Start service and use net.tcp binding
ServiceHost eventServiceHost = new ServiceHost (typeof (GreetingsService2));
NetTcpBinding tcpBindingpublish = new NetTcpBinding ();
tcpBindingpublish.Security.Mode = SecurityMode.None;
eventServiceHost.AddServiceEndpoint (typeof (IGreetings2), tcpBindingpublish, "net.tcp://localhost:8000/GreetingsService2");
eventServiceHost.Open ();
//Create client proxy
NetTcpBinding clientBinding = new NetTcpBinding ();
clientBinding.Security.Mode = SecurityMode.None;
EndpointAddress ep = new EndpointAddress ("net.tcp://localhost:8000/GreetingsService2");
ClientCallback2 cb = new ClientCallback2 ();
IGreetings2 proxy = DuplexChannelFactory<IGreetings2>.CreateChannel (new InstanceContext (cb), clientBinding, ep);
//Call service
proxy.SendMessage ();
//Wait for callback - sort of hack, but better than using wait handle to possibly block tests.
Thread.Sleep (2000);
//Cleanup
eventServiceHost.Close ();
Assert.IsTrue (CallbackSent2, "#1");
Assert.IsTrue (CallbackReceived2, "#2");
}
public static bool CallbackSent, CallbackReceived;
//Service implementation
[ServiceBehavior (ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class GreetingsService : IGreetings
{
public void SendMessage ()
{
//Make a callback
IGreetingsCallback clientCallback = OperationContext.Current.GetCallbackChannel<IGreetingsCallback> ();
clientCallback.ShowMessage ("Mono and WCF are GREAT!");
CallbackBehaviorAttributeTest.CallbackSent = true;
}
}
// Client callback interface implementation
[CallbackBehavior (ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)]
public class ClientCallback : IGreetingsCallback
{
public void ShowMessage (string message)
{
CallbackBehaviorAttributeTest.CallbackReceived = true;
}
}
[ServiceContract (CallbackContract = typeof (IGreetingsCallback))]
public interface IGreetings
{
[OperationContract (IsOneWay = true)]
void SendMessage ();
}
[ServiceContract]
public interface IGreetingsCallback
{
[OperationContract (IsOneWay = true)]
void ShowMessage (string message);
}
public static bool CallbackSent2, CallbackReceived2;
//Service implementation
[ServiceBehavior (ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
public class GreetingsService2 : IGreetings2
{
public void SendMessage ()
{
//Make a callback
IGreetingsCallback2 clientCallback = OperationContext.Current.GetCallbackChannel<IGreetingsCallback2> ();
clientCallback.ShowMessage ("Mono and WCF are GREAT!");
CallbackBehaviorAttributeTest.CallbackSent2 = true;
}
}
// Client callback interface implementation
[CallbackBehavior (ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)]
public class ClientCallback2 : IGreetingsCallback2
{
public void ShowMessage (string message)
{
CallbackBehaviorAttributeTest.CallbackReceived2 = true;
}
}
[ServiceContract (CallbackContract = typeof (IGreetingsCallback2))]
public interface IGreetings2
{
[OperationContract (IsOneWay = false)]
void SendMessage ();
}
[ServiceContract]
public interface IGreetingsCallback2
{
[OperationContract (IsOneWay = false)]
void ShowMessage (string message);
}
#endregion
#region ConcurrencyMode testing
ManualResetEvent wait_handle = new ManualResetEvent (false);
[Test]
[Category ("NotWorking")]
public void ConcurrencyModeSingleAndCallbackInsideServiceMethod ()
{
var host = new ServiceHost (typeof (TestService));
var binding = new NetTcpBinding ();
binding.Security.Mode = SecurityMode.None;
host.AddServiceEndpoint (typeof (ITestService), binding, new Uri ("net.tcp://localhost:18080"));
host.Description.Behaviors.Find<ServiceDebugBehavior> ().IncludeExceptionDetailInFaults = true;
host.Open ();
try {
var cf = new DuplexChannelFactory<ITestService> (new TestCallback (), binding, new EndpointAddress ("net.tcp://localhost:18080"));
var ch = cf.CreateChannel ();
ch.DoWork ("test");
wait_handle.WaitOne (10000);
Assert.Fail ("should fail");
} catch (FaultException) {
// expected.
} finally {
Thread.Sleep (1000);
}
host.Close ();
}
[ServiceContract (CallbackContract = typeof (ITestCallback))]
public interface ITestService
{
[OperationContract (IsOneWay = false)] // ConcurrencyMode error as long as IsOneWay == false.
void DoWork (string name);
}
public interface ITestCallback
{
[OperationContract (IsOneWay = false)]
void Report (string result);
}
public class TestService : ITestService
{
public void DoWork (string name)
{
var cb = OperationContext.Current.GetCallbackChannel<ITestCallback> ();
cb.Report ("OK");
Assert.Fail ("callback should have failed");
}
}
public class TestCallback : ITestCallback
{
public void Report (string result)
{
Assert.Fail ("should not reach here");
}
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,197 @@
//
// ChannelFactoryTest.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 NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class ChannelFactoryTest
{
class SimpleChannelFactory
: ChannelFactory
{
public SimpleChannelFactory ()
: base ()
{
}
protected override TimeSpan DefaultCloseTimeout {
get { return TimeSpan.FromMinutes (1); }
}
protected override TimeSpan DefaultOpenTimeout {
get { return TimeSpan.FromMinutes (1); }
}
protected override ServiceEndpoint CreateDescription ()
{
return new ServiceEndpoint (ContractDescription.GetContract (typeof(ICtorUseCase2)));
}
public void InitEndpoint (Binding b, EndpointAddress addr)
{
base.InitializeEndpoint (b, addr);
}
public void InitEndpoint (string configName, EndpointAddress addr)
{
base.InitializeEndpoint (configName, addr);
}
public void ApplyConfig (string configName)
{
base.ApplyConfiguration (configName);
}
}
[Test]
public void InitializeEndpointTest1 ()
{
SimpleChannelFactory factory = new SimpleChannelFactory ();
Assert.AreEqual (null, factory.Endpoint, "#01");
Binding b = new WSHttpBinding ();
factory.InitEndpoint (b, null);
Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
Assert.AreEqual (null, factory.Endpoint.Address, "#03");
Assert.AreEqual (typeof (ICtorUseCase2), factory.Endpoint.Contract.ContractType, "#04");
}
[Test]
[Ignore ("fails under .NET; I never bothered to fix the test")]
public void InitializeEndpointTest2 ()
{
SimpleChannelFactory factory = new SimpleChannelFactory ();
Assert.AreEqual (null, factory.Endpoint, "#01");
factory.InitEndpoint ("CtorUseCase2_1", null);
Assert.AreEqual (typeof (BasicHttpBinding), factory.Endpoint.Binding.GetType (), "#02");
Assert.AreEqual (new EndpointAddress ("http://test2_1"), factory.Endpoint.Address, "#03");
Assert.AreEqual (typeof (ICtorUseCase2), factory.Endpoint.Contract.ContractType, "#04");
}
[Test]
[Ignore ("fails under .NET; I never bothered to fix the test")]
public void InitializeEndpointTest3 ()
{
SimpleChannelFactory factory = new SimpleChannelFactory ();
Assert.AreEqual (null, factory.Endpoint, "#01");
factory.InitEndpoint ("CtorUseCase2_1", null);
Binding b = new WSHttpBinding ();
factory.InitEndpoint (b, null);
Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
Assert.AreEqual (null, factory.Endpoint.Address, "#03");
}
[Test]
[Ignore ("fails under .NET; I never bothered to fix the test")]
public void ApplyConfigurationTest1 ()
{
SimpleChannelFactory factory = new SimpleChannelFactory ();
Binding b = new WSHttpBinding ();
factory.InitEndpoint (b, null);
factory.ApplyConfig ("CtorUseCase2_1");
Assert.AreEqual (new EndpointAddress ("http://test2_1"), factory.Endpoint.Address, "#03");
Assert.AreEqual (b, factory.Endpoint.Binding, "#02");
}
[Test]
[Ignore ("fails under .NET; I never bothered to fix the test")]
public void ApplyConfigurationTest2 ()
{
SimpleChannelFactory factory = new SimpleChannelFactory ();
Binding b = new WSHttpBinding ();
factory.InitEndpoint (b, new EndpointAddress ("http://test"));
factory.ApplyConfig ("CtorUseCase2_2");
Assert.AreEqual (new EndpointAddress ("http://test"), factory.Endpoint.Address, "#03");
Assert.IsNotNull (factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> (), "#04");
Assert.AreEqual (true, factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> ().IncludeExceptionDetailInFaults, "#04");
factory.ApplyConfig ("CtorUseCase2_3");
Assert.IsNotNull (factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> (), "#04");
Assert.AreEqual (false, factory.Endpoint.Behaviors.Find <CallbackDebugBehavior> ().IncludeExceptionDetailInFaults, "#04");
}
[Test]
public void DescriptionProperties ()
{
Binding b = new BasicHttpBinding ();
ChannelFactory<IFoo> f = new ChannelFactory<IFoo> (b);
// FIXME: it's not working now (though this test is silly to me.)
//Assert.IsNull (f.Description.ChannelType, "ChannelType");
// FIXME: it's not working now
//Assert.AreEqual (1, f.Endpoint.Behaviors.Count, "Behaviors.Count");
//ClientCredentials cred = f.Endpoint.Behaviors [0] as ClientCredentials;
//Assert.IsNotNull (cred, "Behaviors contains ClientCredentials");
Assert.IsNotNull (f.Endpoint, "Endpoint");
Assert.AreEqual (b, f.Endpoint.Binding, "Endpoint.Binding");
Assert.IsNull (f.Endpoint.Address, "Endpoint.Address");
// You can examine this silly test on .NET.
// Funky, ContractDescription.GetContract(
// typeof (IRequestChannel)) also fails to raise an
// error.
//Assert.AreEqual ("IRequestChannel", f.Description.Endpoint.Contract.Name, "Endpoint.Contract");
}
public class MyChannelFactory<TChannel>
: ChannelFactory<TChannel>
{
public MyChannelFactory (Type type)
: base (type)
{
}
}
[ServiceContract]
public interface IFoo
{
[OperationContract]
string Echo (string msg);
}
public class Foo : IFoo
{
public string Echo (string msg)
{
return msg;
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ArgumentTypeNotInterface ()
{
new MyChannelFactory<IFoo> (typeof (Foo));
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,149 @@
//
// ClientBase_InteractiveChannelInitializerTest.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.IO;
using System.Net.Sockets;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
// FIXME: it does not contain testcase for successful initialization yet
// (MyChannelInitializer implementation hangs on .NET)
public class ClientBase_InteractiveChannelInitializerTest
{
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void NotAllowedInitializationUI ()
{
var f = new FooProxy (new BasicHttpBinding (), new EndpointAddress ("http://localhost:37564"));
f.Endpoint.Contract.Behaviors.Add (new MyContractBehavior ());
f.InnerChannel.AllowInitializationUI = false;
f.DisplayInitializationUI ();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void OpenBeforeDisplayInitializationUI ()
{
var f = new FooProxy (new BasicHttpBinding (), new EndpointAddress ("http://localhost:37564"));
f.Endpoint.Contract.Behaviors.Add (new MyContractBehavior ());
f.Open ();
}
public class MyContractBehavior2 : MyContractBehavior
{
}
public class MyContractBehavior : IContractBehavior
{
public void AddBindingParameters (ContractDescription contractDescription, ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior (ContractDescription contractDescription, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.InteractiveChannelInitializers.Add (new MyChannelInitializer ());
}
public void ApplyDispatchBehavior (ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
{
}
public void Validate (ContractDescription contractDescription, ServiceEndpoint endpoint)
{
}
}
public class MyChannelInitializer : IInteractiveChannelInitializer
{
delegate void DoWork ();
DoWork d;
static int instance;
int number;
public MyChannelInitializer ()
{
number = instance++;
}
public IAsyncResult BeginDisplayInitializationUI (IClientChannel channel, AsyncCallback callback, object state)
{
Console.WriteLine ("Begin");
d = new DoWork (DisplayInitializationUI);
return d.BeginInvoke (null, null);
}
public void EndDisplayInitializationUI (IAsyncResult result)
{
Console.WriteLine ("End");
d.EndInvoke (result);
}
public void DisplayInitializationUI ()
{
Console.WriteLine ("Core: " + number);
}
}
public class FooProxy : ClientBase<IFoo>, IFoo
{
public FooProxy (Binding binding, EndpointAddress address)
: base (binding, address)
{
}
public string Echo (string msg)
{
return Channel.Echo (msg);
}
}
[ServiceContract]
public interface IFoo
{
[OperationContract]
string Echo (string input);
}
public class FooService : IFoo
{
public string Echo (string input)
{
return input;
}
}
}
}

View File

@@ -0,0 +1,59 @@
//
// CommonUseCases.cs
//
// Author:
// Eyal Alaluf
//
// Copyright (C) 2008 Mainsoft Co. http://www.mainsoft.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 NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
// Use case with one endpoint configuration.
[ServiceContract]
public interface ICtorUseCase1
{
[OperationContract]
string Echo (string msg);
}
// Use case with multiple endpoint configurations.
[ServiceContract(ConfigurationName = "CtorUseCase2")]
public interface ICtorUseCase2
{
[OperationContract]
string Echo (string msg);
}
// Use case without endpoint configuration.
[ServiceContract(ConfigurationName = "CtorUseCase3")]
public interface ICtorUseCase3
{
[OperationContract]
string Echo (string msg);
}
}

View File

@@ -0,0 +1,263 @@
//
// Constants.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.Xml;
namespace System.ServiceModel
{
internal class Constants
{
public const string Soap11 = "http://schemas.xmlsoap.org/soap/envelope/";
public const string Soap12 = "http://www.w3.org/2003/05/soap-envelope";
public const string WSBasicSecurityProfileCore1 = "http://ws-i.org/profiles/basic-security/core/1.0";
public const string WsaAnonymousUri = "http://www.w3.org/2005/08/addressing/anonymous";
public const string WsaIdentityUri = "http://schemas.xmlsoap.org/ws/2006/02/addressingidentity";
public const string MSSerialization = "http://schemas.microsoft.com/2003/10/Serialization/";
public const string WssKeyIdentifierX509Thumbptint = "http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1";
public const string WssBase64BinaryEncodingType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary";
public const string WssKeyIdentifierEncryptedKey = "http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKeySHA1";
public const string XmlDsig = "http://www.w3.org/2000/09/xmldsig#";
public const string WSSSamlToken = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
public const string WSSX509Token = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3";
public const string WssKeyIdentifierSamlAssertion = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID";
public const string WSSUserNameToken = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken";
public const string WsscContextToken = "http://schemas.xmlsoap.org/ws/2005/02/sc/sct";
public const string WSSKerberosToken = "http://docs.oasis-open.org/wss/oasis-wss-kerberos-token-profile-1.1#GSS_Kerberosv5_AP_REQ";
public const string WSSEncryptedKeyToken = "http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey";
public const string WstNamespace = "http://schemas.xmlsoap.org/ws/2005/02/trust";
public const string WssNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
public const string Wss11Namespace = "http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd";
public const string WspNamespace = "http://schemas.xmlsoap.org/ws/2004/09/policy";
public const string WsaNamespace = "http://www.w3.org/2005/08/addressing";
public const string WsuNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
public const string WsscNamespace = "http://schemas.xmlsoap.org/ws/2005/02/sc";
public const string WsidNamespace = "http://schemas.xmlsoap.org/ws/2005/05/identity";
public const string WstIssueAction = "http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue";
public const string WstRenewAction = "http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Renew";
public const string WstCancelAction = "http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Cancel";
public const string WstValidateAction = "http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Validate";
public const string WstIssueReplyAction = "http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Issue";
public const string WstRenewReplyAction = "http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Renew";
public const string WstCancelReplyAction = "http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Cancel";
public const string WstValidateReplyAction = "http://schemas.xmlsoap.org/ws/2005/02/trust/RSTR/Validate";
public const string WsscDefaultLabel = "WS-SecureConversationWS-SecureConversation";
// .NET BUG: it requires extra white space !
public const string WstBinaryExchangeValueTls = " http://schemas.xmlsoap.org/ws/2005/02/trust/tlsnego";
public const string WstBinaryExchangeValueGss = "http://schemas.xmlsoap.org/ws/2005/02/trust/spnego";
public const string MSTlsnegoTokenContent = "http://schemas.microsoft.com/ws/2006/05/security";
public const string WstTlsnegoProofTokenType = "http://schemas.xmlsoap.org/2005/02/trust/tlsnego#TLS_Wrap";
public const string WstSpnegoProofTokenType = "http://schemas.xmlsoap.org/2005/02/trust/spnego#TLS_Wrap";
public const string WstIssueRequest = "http://schemas.xmlsoap.org/ws/2005/02/trust/Issue";
public const string WstRenewRequest = "http://schemas.xmlsoap.org/ws/2005/02/trust/Renew";
public const string WstCancelRequest = "http://schemas.xmlsoap.org/ws/2005/02/trust/Cancel";
public const string WstValidateRequest = "http://schemas.xmlsoap.org/ws/2005/02/trust/Validate";
public const string WstSymmetricKeyTypeUri = "http://schemas.xmlsoap.org/ws/2005/02/trust/SymmetricKey";
public const string WstAsymmetricKeyTypeUri = "http://schemas.xmlsoap.org/ws/2005/02/trust/AsymmetricKey";
public const string LifetimeFormat = "yyyy-MM-dd'T'HH:mm:ss.fffZ";
// Those OIDs except for Kerberos5 are described here:
// http://www.alvestrand.no/objectid/
// (searching web for those OIDs would give you pointers.)
public const string OidSpnego = "1.3.6.1.5.5.2";
public const string OidNtlmSsp = "1.3.6.1.4.1.311.2.2.10";
public const string OidKerberos5 = "1.2.840.48018.1.2.2";
public const string OidMIT = "1.2.840.113554.1.2.2";
// Peer resolvers
public const string NetPeer = "http://schemas.microsoft.com/net/2006/05/peer";
// 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 Constants ()
{
var d = new XmlDictionary ();
SoapDictionary = d;
foreach (var s in dict_strings)
d.Add (s);
}
public static XmlDictionary SoapDictionary { get; private set; }
}
}

View File

@@ -0,0 +1,121 @@
//
// EndpointAddress10Test.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2007 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 System.Xml.Schema;
using System.Xml.Serialization;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class EndpointAddress10Test
{
[Test]
public void ReadWriteXml ()
{
StringWriter sw = new StringWriter ();
EndpointAddress10 e = EndpointAddress10.FromEndpointAddress (new EndpointAddress ("http://localhost:8080"));
using (XmlWriter xw = XmlWriter.Create (sw)) {
((IXmlSerializable) e).WriteXml (xw);
}
Assert.AreEqual (@"<?xml version=""1.0"" encoding=""utf-16""?><Address xmlns=""http://www.w3.org/2005/08/addressing"">http://localhost:8080/</Address>", sw.ToString ());
// unlike WriteXml, ReadXml expects the root element.
StringReader sr = new StringReader (@"<EndpointReference xmlns=""http://www.w3.org/2005/08/addressing""><Address>http://localhost:8080/</Address></EndpointReference>");
using (XmlReader xr = XmlReader.Create (sr)) {
((IXmlSerializable) e).ReadXml (xr);
}
sr = new StringReader (@"<EndpointReference xmlns=""http://www.w3.org/2005/08/addressing""><Address>http://localhost:8080/</Address></EndpointReference>");
using (XmlReader xr = XmlReader.Create (sr))
EndpointAddress.ReadFrom (AddressingVersion.WSAddressing10, xr);
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadWriteXml2 ()
{
var sr = new StringReader (@"<Address>http://localhost:8080/</Address>");
using (XmlReader xr = XmlReader.Create (sr))
EndpointAddress.ReadFrom (AddressingVersion.WSAddressing10, xr);
}
[Test]
public void SerializeDeserialize ()
{
StringWriter sw = new StringWriter ();
EndpointAddress10 e = EndpointAddress10.FromEndpointAddress (new EndpointAddress ("http://localhost:8080"));
XmlSerializer xs = new XmlSerializer (typeof (EndpointAddress10));
sw = new StringWriter ();
using (XmlWriter xw = XmlWriter.Create (sw)) {
xs.Serialize (xw, e);
}
Assert.AreEqual (@"<?xml version=""1.0"" encoding=""utf-16""?><EndpointReference xmlns=""http://www.w3.org/2005/08/addressing""><Address>http://localhost:8080/</Address></EndpointReference>", sw.ToString ());
StringReader sr = new StringReader (sw.ToString ());
using (XmlReader xr = XmlReader.Create (sr)) {
xs.Deserialize (xr);
}
}
[Test]
public void GetSchema ()
{
// actually it just returns null. That makes sense
// since there's no way to include reasonable claim
// schemas.
EndpointAddress10.FromEndpointAddress (new EndpointAddress ("http://localhost:8080"));
XmlSchemaSet xss = new XmlSchemaSet ();
XmlQualifiedName q = EndpointAddress10.GetSchema (xss);
Assert.AreEqual (1, xss.Count, "#1");
Assert.AreEqual ("EndpointReferenceType", q.Name, "#2");
Assert.AreEqual ("http://www.w3.org/2005/08/addressing", q.Namespace, "#2");
foreach (XmlSchema xs in xss.Schemas ()) {
Assert.AreEqual ("http://www.w3.org/2005/08/addressing", xs.TargetNamespace, "#4");
}
}
[Test]
public void IXmlSerializableGetSchema ()
{
// actually it just returns null.
EndpointAddress10 e = EndpointAddress10.FromEndpointAddress (new EndpointAddress ("http://localhost:8080"));
XmlSchema xs = ((IXmlSerializable) e).GetSchema ();
Assert.IsNull (xs);
}
}
}

View File

@@ -0,0 +1,65 @@
//
// EndpointAddressBuilderTest.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.IO;
using System.ServiceModel;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class EndpointAddressBuilderTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ToEndpointAddressWithoutReader ()
{
new EndpointAddressBuilder ().ToEndpointAddress ();
}
[Test]
public void UsageExample ()
{
var eb = new EndpointAddressBuilder ();
var dr = XmlDictionaryReader.CreateDictionaryReader (XmlReader.Create (new StringReader ("<foo/>")));
eb.SetExtensionReader (dr);
Assert.AreEqual (ReadState.EndOfFile, dr.ReadState, "#1");
var xr = eb.GetReaderAtExtensions ();
xr.ReadOuterXml ();
xr = eb.GetReaderAtExtensions (); // do not return the same XmlReader
Assert.AreEqual (ReadState.Interactive, xr.ReadState, "#2");
xr.ReadOuterXml ();
eb.SetExtensionReader (null); // allowed
Assert.IsNull (eb.GetReaderAtExtensions (), "#3");
}
}
}

View File

@@ -0,0 +1,437 @@
//
// EndpointBehaviorCollectionTest.cs
//
// Authors:
// Duncan Mak <duncan@ximian.com>
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-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.IO;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class EndpointAddressTest
{
EndpointAddress address;
string namespace_uri = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
[Test]
public void AnonymousUri ()
{
Assert.AreEqual ("http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous", EndpointAddress.AnonymousUri.AbsoluteUri, "#1");
address = new EndpointAddress ("http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous");
Assert.IsTrue (address.IsAnonymous, "#2");
Assert.IsFalse (address.IsNone, "#3");
}
[Test]
public void AnonymousUri2 ()
{
address = new EndpointAddress ("http://www.w3.org/2005/08/addressing/anonymous");
Assert.AreEqual ("http://www.w3.org/2005/08/addressing/anonymous", address.Uri.AbsoluteUri, "#1");
Assert.IsFalse (address.IsAnonymous, "#2");
Assert.IsFalse (address.IsNone, "#3");
}
[Test]
public void NoneUri ()
{
Assert.AreEqual ("http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/None", EndpointAddress.NoneUri.AbsoluteUri, "#1");
address = new EndpointAddress ("http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/None");
Assert.IsFalse (address.IsAnonymous, "#2");
Assert.IsTrue (address.IsNone, "#3");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNullString ()
{
new EndpointAddress ((string) null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorRelativeUri ()
{
new EndpointAddress (new Uri (String.Empty, UriKind.RelativeOrAbsolute));
}
[Test]
public void Headers ()
{
EndpointAddress e = new EndpointAddress ("urn:foo");
Assert.IsNotNull (e.Headers, "#1");
// This code results in NullReferenceException, which
// is nasty.
//Assert.AreEqual (0, e.Headers.Count, "#2");
}
[Test]
public void EqualsTest ()
{
address = new EndpointAddress ("urn:foo");
Assert.IsFalse (address == null, "#1"); // don't throw NullReferenceException
Assert.IsTrue ((EndpointAddress) null == null, "#2");
Assert.IsTrue (address == new EndpointAddress ("urn:foo"), "#3");
}
[Test]
public void ReadFrom0 ()
{
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress a = EndpointAddress.ReadFrom (reader);
Assert.IsNotNull (a, "#1");
Assert.AreEqual ("http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous", a.Uri.AbsoluteUri, "#2");
Assert.IsTrue (a.IsAnonymous, "#3");
}
[Test]
public void ReadFrom1 ()
{
string xml = @"<a:ReplyTo xmlns:a='http://schemas.xmlsoap.org/ws/2004/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress a = EndpointAddress.ReadFrom (reader);
Assert.IsNotNull (a, "#1");
Assert.AreEqual ("http://www.w3.org/2005/08/addressing/anonymous", a.Uri.AbsoluteUri, "#2");
Assert.IsFalse (a.IsAnonymous, "#3");
}
[Test]
public void ReadFrom2 ()
{
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress a = EndpointAddress.ReadFrom (AddressingVersion.WSAddressing10, reader);
Assert.IsNotNull (a, "#1");
Assert.AreEqual ("http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous", a.Uri.AbsoluteUri, "#2");
Assert.IsTrue (a.IsAnonymous, "#3");
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFrom2Error ()
{
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
//Reading address with e10 address!
EndpointAddress.ReadFrom (AddressingVersion.WSAddressingAugust2004, reader);
}
[Test]
public void ReadFrom3 ()
{
string xml = @"<a:ReplyTo xmlns:a='http://schemas.xmlsoap.org/ws/2004/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress a = EndpointAddress.ReadFrom (AddressingVersion.WSAddressingAugust2004, reader);
Assert.AreEqual ("http://www.w3.org/2005/08/addressing/anonymous", a.Uri.AbsoluteUri, "#1");
Assert.IsFalse (a.IsAnonymous, "#2");
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFrom3Error ()
{
string xml = @"<a:ReplyTo xmlns:a='http://schemas.xmlsoap.org/ws/2004/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress.ReadFrom (AddressingVersion.WSAddressing10, reader);
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFrom4Error ()
{
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
// null localName and ns
EndpointAddress.ReadFrom (AddressingVersion.WSAddressing10, reader, (string) null, null);
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFrom4Error2 ()
{
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
// null localName and ns
EndpointAddress.ReadFrom (AddressingVersion.WSAddressing10, reader, (XmlDictionaryString) null, null);
}
[Test]
public void ReadFromE10 ()
{
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress10 e10 = EndpointAddress10.FromEndpointAddress (new EndpointAddress (("http://test")));
((IXmlSerializable) e10).ReadXml (reader);
EndpointAddress a = e10.ToEndpointAddress ();
Assert.AreEqual ("http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous", a.Uri.AbsoluteUri, "#1");
Assert.IsTrue (a.IsAnonymous, "#2");
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFromE10Error ()
{
//Address is from August2004 namespace, but reading it with EndpointAddress10
string xml = @"<a:ReplyTo xmlns:a='http://schemas.xmlsoap.org/ws/2004/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress10 e10 = EndpointAddress10.FromEndpointAddress (new EndpointAddress (("http://test")));
((IXmlSerializable) e10).ReadXml (reader);
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFromE10Error2 ()
{
//Missing <Address> element
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'>http://www.w3.org/2005/08/addressing/anonymous</a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress10 e10 = EndpointAddress10.FromEndpointAddress (new EndpointAddress (("http://test")));
((IXmlSerializable) e10).ReadXml (reader);
}
[Test]
public void ReadFromAugust2004 ()
{
string xml = @"<a:ReplyTo xmlns:a='http://schemas.xmlsoap.org/ws/2004/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddressAugust2004 e2k4 = EndpointAddressAugust2004.FromEndpointAddress (new EndpointAddress ("http://test"));
((IXmlSerializable) e2k4).ReadXml (reader);
Console.WriteLine (e2k4.ToEndpointAddress ().Uri.AbsoluteUri);
EndpointAddress a = e2k4.ToEndpointAddress ();
Assert.AreEqual ("http://www.w3.org/2005/08/addressing/anonymous", a.Uri.AbsoluteUri, "#1");
Assert.IsFalse (a.IsAnonymous, "#2");
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFromAugust2004Error ()
{
//Reading address from EndpointAddress10 namespace with EndpointAddressAugust2004
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddressAugust2004 e2k4 = EndpointAddressAugust2004.FromEndpointAddress (new EndpointAddress ("http://test"));
((IXmlSerializable) e2k4).ReadXml (reader);
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFromAugust2004Error2 ()
{
//Missing <Address> element
string xml = @"<a:ReplyTo xmlns:a='http://schemas.xmlsoap.org/ws/2004/08/addressing'>http://www.w3.org/2005/08/addressing/anonymous</a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddressAugust2004 e2k4 = EndpointAddressAugust2004.FromEndpointAddress (new EndpointAddress ("http://test"));
((IXmlSerializable) e2k4).ReadXml (reader);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ReadFromWrongXml ()
{
string xml = @"<a:Address xmlns:a='http://www.w3.org/2005/08/addressing'>http://www.w3.org/2005/08/addressing/anonymous</a:Address>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress.ReadFrom (reader);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ReadFromWrongXml2 ()
{
string xml = @"<a:ReplyTo xmlns:a='http://www.w3.org/2005/08/addressing'>http://www.w3.org/2005/08/addressing/anonymous</a:ReplyTo>";
XmlReader src = XmlReader.Create (new StringReader (xml));
XmlDictionaryReader reader =
XmlDictionaryReader.CreateDictionaryReader (src);
EndpointAddress.ReadFrom (reader);
}
[Test]
public void WriteToAddressingNone ()
{
EndpointAddress a = new EndpointAddress ("http://localhost:8080");
StringWriter sw = new StringWriter ();
XmlWriterSettings xws = new XmlWriterSettings ();
xws.OmitXmlDeclaration = true;
// #1
using (XmlDictionaryWriter xw = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw, xws))) {
a.WriteTo (AddressingVersion.None, xw, "From", "http://www.w3.org/2005/08/addressing");
}
Assert.AreEqual ("<From xmlns=\"http://www.w3.org/2005/08/addressing\">http://localhost:8080/</From>", sw.ToString (), "#1");
// #2
sw = new StringWriter ();
using (XmlDictionaryWriter xw = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw, xws))) {
a.WriteTo (AddressingVersion.None, xw);
}
Assert.AreEqual ("<EndpointReference xmlns=\"http://schemas.microsoft.com/ws/2005/05/addressing/none\">http://localhost:8080/</EndpointReference>", sw.ToString (), "#2");
}
string identity1 = "<Identity xmlns=\"http://schemas.xmlsoap.org/ws/2006/02/addressingidentity\"><KeyInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><X509Data><X509Certificate>MIIBxTCCAS6gAwIBAgIQEOvBwzgWq0aTzEi0qgWLBTANBgkqhkiG9w0BAQUFADAgMR4wHAYDVQQDExVNb25vIFRlc3QgUm9vdCBBZ2VuY3kwHhcNMDYwNzMxMDYxMDI4WhcNMzkxMjMxMDk1OTU5WjAkMSIwIAYDVQQDExlQb3Vwb3Uncy1Tb2Z0d2FyZS1GYWN0b3J5MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQCJI5sOaaEOCuXg2Itq+IVym/g13KwFYlyqJXPcBBs91qO1dpBDxUl19GSLFqHXfbIo4UYJZmEdLcS48yHx1w3AbC1raeH6bYhXqS3Mjj6ZnsJI0CyaUNjQkj4fwC3W8q80CuULmORUa6WJiugl5JT80s8s1iCymLtO1cbL1F+6DwIBETANBgkqhkiG9w0BAQUFAAOBgQA5IxtEKCgG0o6YxVDKRRTfiQY4QiCkHxqgfP2E+Cm6guuHykAFvWFqMUtGZq3yco8u83ZgXtjPphhPuzl8fdJsLTXieERsAbfZwcbp6cssTwsSl4JJviHSN17G3qbo0LH9u1QJHesBaH52Hz2iZaBfClxgUQGeWvO0SW+hZo75hg==</X509Certificate></X509Data></KeyInfo></Identity>";
string C14N (string xml)
{
XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform ();
XmlDocument doc = new XmlDocument ();
doc.LoadXml (xml);
t.LoadInput (doc);
return new StreamReader (t.GetOutput () as Stream).ReadToEnd ();
}
[Test]
public void WriteToWSA10 ()
{
X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.cer");
EndpointAddress a = new EndpointAddress (
new Uri ("http://localhost:8080"),
new X509CertificateEndpointIdentity (cert));
StringWriter sw = new StringWriter ();
XmlWriterSettings xws = new XmlWriterSettings ();
xws.OmitXmlDeclaration = true;
using (XmlDictionaryWriter xw = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw, xws))) {
a.WriteTo (AddressingVersion.WSAddressing10, xw);
}
Assert.AreEqual (C14N ("<EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\"><Address>http://localhost:8080/</Address>" + identity1 + "</EndpointReference>"), C14N (sw.ToString ()), "#2");
}
[Test]
public void WriteContentsToWSA10 ()
{
X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.cer");
EndpointAddress a = new EndpointAddress (
new Uri ("http://localhost:8080"),
new X509CertificateEndpointIdentity (cert));
StringWriter sw = new StringWriter ();
XmlWriterSettings xws = new XmlWriterSettings ();
xws.OmitXmlDeclaration = true;
using (XmlDictionaryWriter xw = XmlDictionaryWriter.CreateDictionaryWriter (XmlWriter.Create (sw, xws))) {
xw.WriteStartElement ("root");
a.WriteContentsTo (AddressingVersion.WSAddressing10, xw);
xw.WriteEndElement ();
}
Assert.AreEqual (C14N ("<root><Address xmlns=\"http://www.w3.org/2005/08/addressing\">http://localhost:8080/</Address>" + identity1 + "</root>"), C14N (sw.ToString ()), "#2");
}
/* GetSchema() does not exist anymore
[Test]
public void GetSchemaTest ()
{
address = new EndpointAddress ("http://tempuri.org/foo");
Assert.IsNull (address.GetSchema ());
}
[Test]
[Category ("NotWorking")]
public void GetSchemaTestWithEmptySet ()
{
XmlSchemaSet set = new XmlSchemaSet ();
Assert.AreEqual (0, set.Count, "#1");
Assert.IsFalse (set.Contains (namespace_uri), "#2");
XmlQualifiedName n = EndpointAddress.GetSchema (set);
// A complete copy of the schema for EndpointReference is added.
Assert.AreEqual (1, set.Count, "#3");
Assert.IsTrue (set.Contains (namespace_uri), "#4");
int count = 5;
foreach (XmlSchema schema in set.Schemas ()) {
Assert.AreEqual (schema.TargetNamespace, n.Namespace, "#" + count++);
Assert.IsTrue (schema.SchemaTypes.Contains (n), "#" + count++);
// This prints out the entire Schema!
// schema.Write (Console.Out);
}
}
*/
}
}

View File

@@ -0,0 +1,51 @@
//
// EndpointBehaviorCollectionTest.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.
//
#if USE_DEPRECATED
using System;
using System.Collections.ObjectModel;
using System.Net.Security;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Description;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class EndpointBehaviorCollectionTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
[Ignore ("It throws NullReferenceException instead")]
public void CtorNullArg ()
{
new EndpointBehaviorCollection (null);
}
}
}
#endif

View File

@@ -0,0 +1,73 @@
//
// EndpointIdentityTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2007 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.IdentityModel.Claims;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
using System.ServiceModel;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class EndpointIdentityTest
{
static readonly X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.cer");
[Test]
public void CreateX509CertificateIdentity ()
{
X509CertificateEndpointIdentity identity =
EndpointIdentity.CreateX509CertificateIdentity (cert)
as X509CertificateEndpointIdentity;
Claim c = identity.IdentityClaim;
Assert.IsNotNull (c, "#1");
Assert.AreEqual (ClaimTypes.Thumbprint, c.ClaimType, "#2");
DataContractSerializer ser = new DataContractSerializer (c.GetType ());
StringWriter sw = new StringWriter ();
XmlWriter xw = XmlWriter.Create (sw);
ser.WriteObject (xw, c);
xw.Close ();
string xml = @"<?xml version=""1.0"" encoding=""utf-16""?><Claim xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.xmlsoap.org/ws/2005/05/identity""><ClaimType>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint</ClaimType><Resource xmlns:d2p1=""http://www.w3.org/2001/XMLSchema"" i:type=""d2p1:base64Binary"">GQ3YHlGQhDF1bvMixHliX4uLjlY=</Resource><Right>http://schemas.xmlsoap.org/ws/2005/05/identity/right/possessproperty</Right></Claim>";
Assert.AreEqual (C14N (xml), C14N (sw.ToString ()), "#3");
Assert.AreEqual ("identity(" + c + ")", identity.ToString (), "#4");
}
string C14N (string xml)
{
XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform ();
XmlDocument doc = new XmlDocument ();
doc.LoadXml (xml);
t.LoadInput (doc);
return new StreamReader (t.GetOutput () as Stream).ReadToEnd ();
}
}
}

View File

@@ -0,0 +1,104 @@
//
// ExtensionCollectionTest.cs
//
// Author:
// Igor Zelmanovich <igorz@mainsoft.com>
//
// Copyright (C) 2008 Mainsoft, Inc. http://www.mainsoft.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.Text;
using NUnit.Framework;
using System.ServiceModel;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class ExtensionCollectionTest
{
class MyExtensibleObject : IExtensibleObject<MyExtensibleObject>
{
IExtensionCollection<MyExtensibleObject> _extensions;
public IExtensionCollection<MyExtensibleObject> Extensions {
get {
if (_extensions == null)
_extensions = new ExtensionCollection<MyExtensibleObject> (this);
return _extensions;
}
}
}
abstract class MyExtensionBase : IExtension<MyExtensibleObject>
{
public bool IsAttached {
get;
private set;
}
public void Attach (MyExtensibleObject owner) {
IsAttached = true;
}
public void Detach (MyExtensibleObject owner) {
IsAttached = false;
}
}
class MyExtension1 : MyExtensionBase
{
}
class MyExtension2 : MyExtensionBase
{
}
[Test]
public void Add_Remove_Call_Attach () {
MyExtensibleObject extObj = new MyExtensibleObject ();
MyExtension1 ext = new MyExtension1 ();
Assert.AreEqual (false, ext.IsAttached, "IsAttached #1");
extObj.Extensions.Add (ext);
Assert.AreEqual (true, ext.IsAttached, "IsAttached #2");
extObj.Extensions.Remove (ext);
Assert.AreEqual (false, ext.IsAttached, "IsAttached #3");
}
[Test]
public void Clear_Calls_Attach () {
MyExtensibleObject extObj = new MyExtensibleObject ();
MyExtension1 ext1 = new MyExtension1 ();
MyExtension2 ext2 = new MyExtension2 ();
extObj.Extensions.Add (ext1);
extObj.Extensions.Add (ext2);
Assert.AreEqual (true, ext1.IsAttached, "IsAttached #1");
Assert.AreEqual (true, ext2.IsAttached, "IsAttached #2");
extObj.Extensions.Clear ();
Assert.AreEqual (false, ext1.IsAttached, "IsAttached #3");
Assert.AreEqual (false, ext2.IsAttached, "IsAttached #4");
}
}
}

View File

@@ -0,0 +1,85 @@
using System;
using System.ServiceModel;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class FaultCodeTest
{
FaultCode code;
[Test]
public void TestDefaults ()
{
code = new FaultCode ("foo");
Assert.AreEqual ("foo", code.Name);
Assert.AreEqual (String.Empty, code.Namespace);
Assert.AreEqual (null, code.SubCode);
}
[Test]
public void TestReceiverFaultCode ()
{
code = FaultCode.CreateReceiverFaultCode ("foo", "bar");
Assert.IsTrue (code.IsReceiverFault);
Assert.AreEqual ("Receiver", code.Name);
Assert.AreEqual (String.Empty, code.Namespace);
Assert.AreEqual ("foo", code.SubCode.Name);
Assert.AreEqual ("bar", code.SubCode.Namespace);
code = new FaultCode ("Receiver");
Assert.IsTrue (code.IsReceiverFault);
code = new FaultCode ("something else");
Assert.IsFalse (code.IsReceiverFault);
}
[Test]
public void TestSenderFaultCode ()
{
code = FaultCode.CreateSenderFaultCode ("foo", "bar");
Assert.IsTrue (code.IsSenderFault);
Assert.AreEqual ("Sender", code.Name);
Assert.AreEqual (String.Empty, code.Namespace);
Assert.AreEqual ("foo", code.SubCode.Name);
Assert.AreEqual ("bar", code.SubCode.Namespace);
code = new FaultCode ("Sender");
Assert.IsTrue (code.IsSenderFault);
code = new FaultCode ("something else");
Assert.IsFalse (code.IsReceiverFault);
}
[Test]
public void TestIsPredefinedCode ()
{
code = new FaultCode ("foo");
Assert.IsTrue (code.IsPredefinedFault);
code = new FaultCode ("foo", String.Empty);
Assert.IsTrue (code.IsPredefinedFault);
code = new FaultCode ("foo", "bar");
Assert.IsFalse (code.IsPredefinedFault);
code = FaultCode.CreateReceiverFaultCode (new FaultCode ("foo", "bar"));
Assert.IsTrue (code.IsPredefinedFault);
Assert.IsFalse (code.SubCode.IsPredefinedFault);
code = FaultCode.CreateReceiverFaultCode (new FaultCode ("foo"));
Assert.IsTrue (code.IsPredefinedFault);
Assert.IsTrue (code.SubCode.IsPredefinedFault);
}
[Test]
public void TestNamespace ()
{
code = new FaultCode ("foo");
Assert.AreEqual (String.Empty, code.Namespace);
Assert.IsTrue (code.IsPredefinedFault);
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class FaultContractAttributeTest
{
[Test]
public void Defaults ()
{
var a = new FaultContractAttribute (typeof (MyDetail));
Assert.AreEqual (typeof (MyDetail), a.DetailType, "#1");
Assert.IsNull (a.Action, "#2");
Assert.IsNull (a.Name, "#3");
Assert.IsNull (a.Namespace, "#4");
}
class MyDetail
{
}
}
}

View File

@@ -0,0 +1,136 @@
//
// FaultReasonTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc.
//
// 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.Globalization;
using System.ServiceModel;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class FaultReasonTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNullFaultReasonText ()
{
new FaultReason ((FaultReasonText) null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNullEnumerable ()
{
new FaultReason ((IEnumerable<FaultReasonText>) null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CtorEmptyEnumerable ()
{
new FaultReason (new List<FaultReasonText> ());
}
[Test]
public void Simple ()
{
FaultReason r = new FaultReason ("testing");
FaultReasonText t = r.GetMatchingTranslation ();
Assert.IsNotNull (t);
Assert.AreEqual ("testing", t.Text, "#1");
Assert.AreEqual (CultureInfo.CurrentCulture.Name,
t.XmlLang, "#2");
}
[Test]
public void MultipleLanguages ()
{
string current = CultureInfo.CurrentCulture.Name;
FaultReason r = new FaultReason (new FaultReasonText [] {
new FaultReasonText ("hello"),
new FaultReasonText ("hola", "es-ES"),
new FaultReasonText ("bonjour", "fr")});
// CurrentCulture
FaultReasonText t = r.GetMatchingTranslation (
CultureInfo.CurrentCulture);
Assert.IsNotNull (t);
Assert.AreEqual ("hello", t.Text, "#1");
Assert.AreEqual (current, t.XmlLang, "#2");
// non-neutral name, get by non-neutral culture
t = r.GetMatchingTranslation (
new CultureInfo ("es-ES"));
Assert.IsNotNull (t);
Assert.AreEqual ("hola", t.Text, "#3");
Assert.AreEqual ("es-ES", t.XmlLang, "#4");
// .ctor(non-neutral name), get by neutral culture
t = r.GetMatchingTranslation (new CultureInfo ("es"));
Assert.IsNotNull (t);
Assert.AreEqual ("hello", t.Text, "#5");
Assert.AreEqual (current, t.XmlLang, "#6");
// .ctor(neutral name), get by non-neutral culture
t = r.GetMatchingTranslation (
new CultureInfo ("fr-FR"));
Assert.IsNotNull (t);
Assert.AreEqual ("bonjour", t.Text, "#7");
Assert.AreEqual ("fr", t.XmlLang, "#8");
}
[Test]
public void NoCurrentCulture ()
{
string current = CultureInfo.CurrentCulture.Name;
FaultReason r = new FaultReason (new FaultReasonText [] {
new FaultReasonText ("hola", "es-ES"),
new FaultReasonText ("bonjour", "fr")});
// CurrentCulture
FaultReasonText t = r.GetMatchingTranslation (
CultureInfo.CurrentCulture);
Assert.IsNotNull (t);
// seems like the first item is used.
Assert.AreEqual ("hola", t.Text, "#1");
Assert.AreEqual ("es-ES", t.XmlLang, "#2");
// InvariantCulture
t = r.GetMatchingTranslation (
CultureInfo.InvariantCulture);
Assert.IsNotNull (t);
// seems like the first item is used.
Assert.AreEqual ("hola", t.Text, "#3");
Assert.AreEqual ("es-ES", t.XmlLang, "#4");
}
}
}

View File

@@ -0,0 +1,328 @@
//
// IntegratedConnectionTest.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.IO;
using System.Net;
using System.Net.Security;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Threading;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
// FIXME: uncomment when NUnit tests on HTTP connection got as
// stable as non-nunit samples.
[TestFixture]
public class IntegratedConnectionTest
{
[Test]
[Ignore ("With Orcas it does not work fine")]
// It is almost identical to samples/basic-http-binding
public void SimpleHttpConnection ()
{
// Service
ServiceHost host = new ServiceHost (typeof (Foo));
try {
Binding binding = new BasicHttpBinding ();
binding.SendTimeout = binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
ServiceEndpoint se = host.AddServiceEndpoint ("MonoTests.System.ServiceModel.IFoo",
binding, new Uri ("http://localhost:37564"));
host.Open ();
// Client
ChannelFactory<IFoo> cf = new ChannelFactory<IFoo> (
new BasicHttpBinding (),
new EndpointAddress ("http://localhost:37564/"));
IFoo foo = cf.CreateChannel ();
Assert.AreEqual ("Test for EchoTest for Echo", foo.Echo ("Test for Echo"));
} finally {
if (host.State == CommunicationState.Opened)
host.Close ();
}
}
[Test]
[Ignore ("With Orcas it does not work fine")]
public void SimpleClientBase ()
{
// Service
ServiceHost host = new ServiceHost (typeof (Foo2));
try {
Binding binding = new BasicHttpBinding ();
binding.SendTimeout = binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
host.AddServiceEndpoint ("MonoTests.System.ServiceModel.IFoo2",
binding, new Uri ("http://localhost:37564"));
host.Open ();
// Client
Foo2Proxy proxy = new Foo2Proxy (
new BasicHttpBinding (),
new EndpointAddress ("http://localhost:37564/"));
proxy.Open ();
try {
Assert.AreEqual ("TEST FOR ECHOTEST FOR ECHO",
proxy.Echo ("TEST FOR ECHO"));
} finally {
proxy.Close ();
}
} finally {
// Service
if (host.State == CommunicationState.Opened)
host.Close ();
}
}
[Test]
[Ignore ("With Orcas it does not work fine")]
public void ExchangeMetadata ()
{
// Service
ServiceHost host = new ServiceHost (typeof (MetadataExchange));
try {
Binding binding = new BasicHttpBinding ();
binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
host.AddServiceEndpoint ("IMetadataExchange",
binding, new Uri ("http://localhost:37564"));
host.Open ();
// Client
MetadataExchangeProxy proxy = new MetadataExchangeProxy (
new BasicHttpBinding (),
new EndpointAddress ("http://localhost:37564/"));
proxy.Open ();
try {
Message req = Message.CreateMessage (MessageVersion.Soap11, "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get");
Message res = proxy.Get (req);
} finally {
proxy.Close ();
}
} finally {
// Service
if (host.State == CommunicationState.Opened)
host.Close ();
}
}
[ServiceContract(SessionMode = SessionMode.Required)]
interface IFoo3
{
[OperationContract]
int GetInstanceCounter ();
}
[ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSession)]
class Foo3 : IFoo3, IDisposable
{
public static int CreatedInstances { get; set; }
public static int DisposedInstances { get; set; }
public static int InstanceCounter {
get { return CreatedInstances - DisposedInstances; }
}
public Foo3 ()
{
CreatedInstances++;
}
public int GetInstanceCounter ()
{
return InstanceCounter;
}
public virtual void Dispose ()
{
DisposedInstances++;
}
}
private void TestSessionbehaviour (Binding binding, Uri address)
{
ServiceHost host = new ServiceHost (typeof (Foo3), address);
host.AddServiceEndpoint (typeof (IFoo3), binding, address);
host.Description.Behaviors.Add (new ServiceThrottlingBehavior () { MaxConcurrentSessions = 1 });
Foo3.CreatedInstances = Foo3.DisposedInstances = 0; // Reset
host.Open ();
Assert.AreEqual (0, Foo3.InstanceCounter, "Initial state wrong"); // just to be sure
var cd = (ChannelDispatcher) host.ChannelDispatchers [0];
for (int i = 1; i <= 3; ++i) {
var factory = new ChannelFactory<IFoo3Client> (binding, address.ToString ());
var proxy = factory.CreateChannel ();
Assert.AreEqual (1, proxy.GetInstanceCounter (), "One server instance after first call in session #" + i);
Assert.AreEqual (1, proxy.GetInstanceCounter (), "One server instance after second call in session #" + i);
factory.Close (); // should close session even when no IsTerminating method has been invoked
Thread.Sleep (500); // give WCF time to dispose service object
Assert.AreEqual (0, Foo3.InstanceCounter, "Service instances must be disposed after channel is closed, in session #" + i);
Assert.AreEqual (i, Foo3.CreatedInstances, "One new instance per session, in session #" + i);
}
host.Close ();
}
interface IFoo3Client : IFoo3, IClientChannel {}
[Test (Description = "Tests InstanceContextMode.PerSession behavior for NetTcp binding")]
public void TestSessionInstancesNetTcp ()
{
Binding binding = new NetTcpBinding (SecurityMode.None, false);
Uri address = new Uri (binding.Scheme + "://localhost:9999/test");
TestSessionbehaviour (binding, address);
}
[Test (Description = "Tests InstanceContextMode.PerSession behavior for WsHttp binding")]
[Category ("NotWorking")] // no working WSHttpBinding in mono.
public void TestSessionInstancesWsHttp ()
{
Binding binding = new WSHttpBinding (SecurityMode.None, true);
Uri address = new Uri (binding.Scheme + "://localhost:9999/test");
TestSessionbehaviour(binding, address);
}
}
#region SimpleConnection classes
[ServiceContract]
public interface IFoo
{
[OperationContract]
string Echo (string msg);
}
class Foo : IFoo
{
public string Echo (string msg)
{
return msg + msg;
}
}
// This is manually created type for strongly typed request.
[DataContract (Name = "Echo", Namespace = "http://tempuri.org/")]
public class EchoType
{
public EchoType (string msg)
{
this.msg = msg;
}
[DataMember]
public string msg = "test";
}
#endregion
#region SampleClientBase classes
[ServiceContract]
public interface IFoo2
{
[OperationContract]
string Echo (string msg);
}
class Foo2 : IFoo2
{
public string Echo (string msg)
{
return msg + msg;
}
}
public class Foo2Proxy : ClientBase<IFoo2>, IFoo2
{
public Foo2Proxy (Binding binding, EndpointAddress address)
: base (binding, address)
{
}
public string Echo (string msg)
{
return Channel.Echo (msg);
}
}
#endregion
#region ExchangeMetadata classes
class MetadataExchange : IMetadataExchange
{
public Message Get (Message request)
{
XmlDocument doc = new XmlDocument ();
doc.AppendChild (doc.CreateElement ("Metadata", "http://schemas.xmlsoap.org/ws/2004/09/mex"));
return Message.CreateMessage (request.Version,
"http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse",
new XmlNodeReader (doc));
}
public IAsyncResult BeginGet (Message request, AsyncCallback cb, object state)
{
throw new NotImplementedException ();
}
public Message EndGet (IAsyncResult result)
{
throw new NotImplementedException ();
}
}
public class MetadataExchangeProxy : ClientBase<IMetadataExchange>, IMetadataExchange
{
public MetadataExchangeProxy (Binding binding, EndpointAddress address)
: base (binding, address)
{
}
public Message Get (Message request)
{
return Channel.Get (request);
}
public IAsyncResult BeginGet (Message request, AsyncCallback callback, object state)
{
throw new NotImplementedException ();
}
public Message EndGet (IAsyncResult result)
{
throw new NotImplementedException ();
}
}
#endregion
}

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