diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2009-10-15 11:08:33 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2009-10-15 11:08:33 +0400 |
commit | 6972c12e9fa00f77c9f62e349705b10a6fc6d4e4 (patch) | |
tree | caa3f3bcc53c3ad27cda773cf85d38a80a822207 | |
parent | d5c703d3f1ed803d6e666cceeb60d606ae73b2aa (diff) |
2009-10-15 Atsushi Enomoto <atsushi@ximian.com>
* ServiceHostBase.cs : on opening the host, check service endpoints
to make sure if there is at least one "non-mex" endpoint.
Fix couple of typos.
* ServiceHostBaseTest.cs : add test for checking non-mex contract
existence.
svn path=/trunk/mcs/; revision=144176
4 files changed, 49 insertions, 14 deletions
diff --git a/mcs/class/System.ServiceModel/System.ServiceModel/ChangeLog b/mcs/class/System.ServiceModel/System.ServiceModel/ChangeLog index 2b57726e499..731ea42f750 100755 --- a/mcs/class/System.ServiceModel/System.ServiceModel/ChangeLog +++ b/mcs/class/System.ServiceModel/System.ServiceModel/ChangeLog @@ -1,3 +1,9 @@ +2009-10-15 Atsushi Enomoto <atsushi@ximian.com> + + * ServiceHostBase.cs : on opening the host, check service endpoints + to make sure if there is at least one "non-mex" endpoint. + Fix couple of typos. + 2009-10-09 Atsushi Enomoto <atsushi@ximian.com> * InstanceContext.cs : new constraints on CommunicationObject diff --git a/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs b/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs index 567b0e57c90..b58174b9aaf 100644 --- a/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs +++ b/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.ServiceModel.Channels; using System.ServiceModel.Configuration; using System.ServiceModel.Description; @@ -84,16 +85,17 @@ namespace System.ServiceModel } } - internal Uri CreateUri (string sheme, Uri relatieUri) { - Uri baseUri = base_addresses.Contains (sheme) ? base_addresses [sheme] : null; + internal Uri CreateUri (string scheme, Uri relativeUri) { + Uri baseUri = base_addresses.Contains (scheme) ? base_addresses [scheme] : null; - if (relatieUri == null) + if (relativeUri == null) return baseUri; - if (relatieUri.IsAbsoluteUri) - return relatieUri; + if (relativeUri.IsAbsoluteUri) + return relativeUri; if (baseUri == null) return null; - return new Uri (baseUri, relatieUri); + var s = relativeUri.ToString (); + return new Uri (baseUri, s.Length > 0 && s [0] == '/' ? '.' + s : s); } public ChannelDispatcherCollection ChannelDispatchers { @@ -217,13 +219,14 @@ namespace System.ServiceModel return help_page_contract; case "IMetadataExchange": // this is certainly looking special (or we may - // be missing something around ServiceMetadataExtension) - // FIXME: this check breaks initialization by configuration - // (as ApplyConfiguration() processes all <endpoint> elements - // before ServiceMetadataBehavior.ApplyDispatchBehavior()). - // So, disable it so far. (it is mostly harmless). - //if (Extensions.Find<ServiceMetadataExtension> () == null) - // break; + // be missing something around ServiceMetadataExtension). + // It seems .NET WCF has some "infrastructure" + // endpoints. .NET ServiceHost fails to Open() + // if it was added only IMetadataExchange + // endpoint (and you'll see the word + // "infrastructure" in the exception message). + if (Description.Behaviors.Find<ServiceMetadataBehavior> () == null) + break; if (mex_contract == null) mex_contract = ContractDescription.GetContract (typeof (IMetadataExchange)); return mex_contract; @@ -406,7 +409,10 @@ namespace System.ServiceModel b.Validate (Description, this); foreach (ServiceEndpoint endPoint in Description.Endpoints) endPoint.Validate (); - } + + if (Description.Endpoints.FirstOrDefault (e => e.Contract != mex_contract) == null) + throw new InvalidOperationException ("The ServiceHost must have at least one application endpoint (that does not include metadata exchange contract) defined by either configuration, behaviors or call to AddServiceEndpoint methods."); + } private void ApplyDispatchBehavior (EndpointDispatcher ed, ServiceEndpoint endPoint) { diff --git a/mcs/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog b/mcs/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog index b2e3dba5ca9..b5e94eed994 100755 --- a/mcs/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog +++ b/mcs/class/System.ServiceModel/Test/System.ServiceModel/ChangeLog @@ -1,3 +1,8 @@ +2009-10-15 Atsushi Enomoto <atsushi@ximian.com> + + * ServiceHostBaseTest.cs : add test for checking non-mex contract + existence. + 2009-10-07 Sebastien Pouliot <sebastien@ximian.com> * OperationContextTest.cs: Add test case for OperationContext.Current diff --git a/mcs/class/System.ServiceModel/Test/System.ServiceModel/ServiceHostBaseTest.cs b/mcs/class/System.ServiceModel/Test/System.ServiceModel/ServiceHostBaseTest.cs index 49b59cf4ab1..99f1fa95b54 100644 --- a/mcs/class/System.ServiceModel/Test/System.ServiceModel/ServiceHostBaseTest.cs +++ b/mcs/class/System.ServiceModel/Test/System.ServiceModel/ServiceHostBaseTest.cs @@ -302,6 +302,24 @@ namespace MonoTests.System.ServiceModel Assert.AreEqual ("http://localhost:37564/", se.ListenUri.AbsoluteUri, "#2"); } + [Test] + [ExpectedException (typeof (InvalidOperationException))] + public void AddServiceEndpointOnlyMex () + { + var host = new ServiceHost (typeof (AllActions), + new Uri ("http://localhost:37564")); + host.Description.Behaviors.Add (new ServiceMetadataBehavior ()); + host.AddServiceEndpoint ("IMetadataExchange", + new BasicHttpBinding (), "/wsdl"); + host.Open (); + try { + // to make sure that throwing IOE from here does not count. + host.Close (); + } catch { + } + Assert.Fail ("should not open"); + } + #region helpers public enum Stage |