2019-04-12 14:10:50 +00:00
|
|
|
#if !MOBILE && !XAMMAC_4_5
|
2014-08-13 10:39:27 +01:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.ServiceModel;
|
|
|
|
using System.ServiceModel.Activation;
|
|
|
|
using System.ServiceModel.Channels;
|
|
|
|
using System.ServiceModel.Web;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
2017-10-19 20:04:20 +00:00
|
|
|
using MonoTests.Helpers;
|
|
|
|
|
2014-08-13 10:39:27 +01:00
|
|
|
namespace MonoTests.System.ServiceModel.Activation
|
|
|
|
{
|
|
|
|
class MyHostFactory : WebScriptServiceHostFactory
|
|
|
|
{
|
|
|
|
public ServiceHost DoCreateServiceHost (Type type, params Uri [] baseAddresses)
|
|
|
|
{
|
|
|
|
return CreateServiceHost (type, baseAddresses);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
public class WebScriptServiceHostFactoryTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void CreateServiceHost ()
|
|
|
|
{
|
2017-10-19 20:04:20 +00:00
|
|
|
var port = NetworkHelpers.FindFreePort ();
|
2014-08-13 10:39:27 +01:00
|
|
|
var f = new MyHostFactory ();
|
2017-10-19 20:04:20 +00:00
|
|
|
var host = f.DoCreateServiceHost (typeof (TestService), new Uri [] {new Uri ($"http://localhost:{port}")});
|
2014-08-13 10:39:27 +01:00
|
|
|
Assert.IsFalse (host is WebServiceHost, "#1");
|
|
|
|
host.Open ();
|
|
|
|
host.Close ();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[ExpectedException (typeof (NotSupportedException))]
|
|
|
|
public void ResponseWrappedIsInvalid ()
|
|
|
|
{
|
2017-10-19 20:04:20 +00:00
|
|
|
var port = NetworkHelpers.FindFreePort ();
|
2014-08-13 10:39:27 +01:00
|
|
|
var f = new MyHostFactory ();
|
2017-10-19 20:04:20 +00:00
|
|
|
var host = f.DoCreateServiceHost (typeof (TestService2), new Uri [] {new Uri ($"http://localhost:{port}")});
|
2014-08-13 10:39:27 +01:00
|
|
|
host.Open (); // should raise an error here.
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
[ExpectedException (typeof (InvalidOperationException))]
|
|
|
|
public void MultipleContract ()
|
|
|
|
{
|
2017-10-19 20:04:20 +00:00
|
|
|
var port = NetworkHelpers.FindFreePort ();
|
2014-08-13 10:39:27 +01:00
|
|
|
var f = new MyHostFactory ();
|
2017-10-19 20:04:20 +00:00
|
|
|
var host = f.DoCreateServiceHost (typeof (TestServiceMultiple), new Uri [] {new Uri ($"http://localhost:{port}")});
|
2014-08-13 10:39:27 +01:00
|
|
|
host.Open ();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
[ServiceContract]
|
|
|
|
public interface ITestService
|
|
|
|
{
|
|
|
|
[OperationContract]
|
|
|
|
string DoWork (string s1, string s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TestService : ITestService
|
|
|
|
{
|
|
|
|
public string DoWork (string s1, string s2)
|
|
|
|
{
|
|
|
|
return s1 + s2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[ServiceContract]
|
|
|
|
public interface ITestService2
|
|
|
|
{
|
|
|
|
[OperationContract]
|
|
|
|
[WebGet (BodyStyle = WebMessageBodyStyle.WrappedResponse)]
|
|
|
|
string DoWork (string s1, string s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TestService2 : ITestService2
|
|
|
|
{
|
|
|
|
public string DoWork (string s1, string s2)
|
|
|
|
{
|
|
|
|
return s1 + s2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TestServiceMultiple : ITestService, ITestService2
|
|
|
|
{
|
|
|
|
public string DoWork (string s1, string s2)
|
|
|
|
{
|
|
|
|
return s1 + s2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|