[ExpectedException (typeof (InvalidOperationException))]
public void AddServiceEndpointMexWithNoImpl ()
{
- using (ServiceHost h = new ServiceHost (typeof (Foo), new Uri ("http://localhost:8080"))) {
+ var port = NetworkHelpers.FindFreePort ();
+ using (ServiceHost h = new ServiceHost (typeof (Foo), new Uri ("http://localhost:" + port))) {
// it expects ServiceMetadataBehavior
h.AddServiceEndpoint (ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding (), "mex");
}
[Test]
public void AddServiceEndpointMetadataExchange ()
{
+ var port = NetworkHelpers.FindFreePort ();
// MyMetadataExchange implements IMetadataExchange
ServiceHost host = new ServiceHost (typeof (MyMetadataExchange));
host.AddServiceEndpoint ("IMetadataExchange",
new BasicHttpBinding (),
- "http://localhost:8080/");
+ "http://localhost:" + port + "/");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void AddServiceEndpointMetadataExchangeFullNameFails ()
{
+ var port = NetworkHelpers.FindFreePort ();
ServiceHost host = new ServiceHost (typeof (MyMetadataExchange));
host.AddServiceEndpoint ("System.ServiceModel.Description.IMetadataExchange",
new BasicHttpBinding (),
- "http://localhost:8080");
+ "http://localhost:" + port);
}
[Test]
}
}
+ [Test]
+ public void InstanceWithSingletonMode_InheritServiceBehavior ()
+ {
+ // # 37035
+
+ var ep = NetworkHelpers.LocalEphemeralEndPoint ().ToString ();
+
+ ChildSingletonService instance = new ChildSingletonService ();
+ ServiceHost host = new ServiceHost (instance);
+
+ host.AddServiceEndpoint (typeof (SingletonService),
+ new BasicHttpBinding (),
+ new Uri ("http://" + ep + "/s3"));
+
+ try {
+ host.Open ();
+ } catch (InvalidOperationException ex) {
+ Assert.Fail ("InstanceContextMode was not inherited from parent, exception was: {0}", ex);
+ } finally {
+ host.Close ();
+ }
+ }
+
[ServiceContract]
interface IBar
{
public class SingletonService
{
[OperationContract]
- public void Process (string input)
+ public virtual void Process (string input)
+ {
+ }
+ }
+
+ public class ChildSingletonService : SingletonService
+ {
+ public override void Process (string input)
{
}
}