2 // WebServiceHostTest.cs
\r
5 // Igor Zelmanovich <igorz@mainsoft.com>
\r
7 // Copyright (C) 2008 Mainsoft, Inc (http://www.mainsoft.com)
\r
9 // Permission is hereby granted, free of charge, to any person obtaining
\r
10 // a copy of this software and associated documentation files (the
\r
11 // "Software"), to deal in the Software without restriction, including
\r
12 // without limitation the rights to use, copy, modify, merge, publish,
\r
13 // distribute, sublicense, and/or sell copies of the Software, and to
\r
14 // permit persons to whom the Software is furnished to do so, subject to
\r
15 // the following conditions:
\r
17 // The above copyright notice and this permission notice shall be
\r
18 // included in all copies or substantial portions of the Software.
\r
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
30 using System.Collections.Generic;
\r
33 using NUnit.Framework;
\r
34 using System.ServiceModel;
\r
35 using System.ServiceModel.Web;
\r
36 using System.ServiceModel.Description;
\r
37 using System.ServiceModel.Dispatcher;
\r
39 namespace MonoTests.System.ServiceModel.Web
\r
42 public class WebServiceHostTest
\r
45 [Category("NotWorking")]
\r
46 public void ServiceDebugBehaviorTest () {
\r
48 var host = new WebServiceHost (typeof (MyService), new Uri ("http://localhost:8080/"));
\r
49 ServiceEndpoint webHttp = host.AddServiceEndpoint ("MonoTests.System.ServiceModel.Web.WebServiceHostTest+MyService", new WebHttpBinding (), "WebHttpBinding");
\r
51 Assert.AreEqual (true, host.Description.Behaviors.Find<ServiceDebugBehavior> ().HttpHelpPageEnabled, "HttpHelpPageEnabled #1");
\r
52 Assert.AreEqual (true, host.Description.Behaviors.Find<ServiceDebugBehavior> ().HttpsHelpPageEnabled, "HttpsHelpPageEnabled #1");
\r
56 Assert.AreEqual (false, host.Description.Behaviors.Find<ServiceDebugBehavior> ().HttpHelpPageEnabled, "HttpHelpPageEnabled #2");
\r
57 Assert.AreEqual (false, host.Description.Behaviors.Find<ServiceDebugBehavior> ().HttpsHelpPageEnabled, "HttpsHelpPageEnabled #2");
\r
63 [Category ("NotWorking")]
\r
64 public void WebHttpBehaviorTest1 () {
\r
66 var host = new WebServiceHost (typeof (MyService), new Uri ("http://localhost:8080/"));
\r
67 ServiceEndpoint webHttp = host.AddServiceEndpoint ("MonoTests.System.ServiceModel.Web.WebServiceHostTest+MyService", new WebHttpBinding (), "WebHttpBinding");
\r
68 ServiceEndpoint basicHttp = host.AddServiceEndpoint ("MonoTests.System.ServiceModel.Web.WebServiceHostTest+MyService", new BasicHttpBinding (), "BasicHttpBinding");
\r
70 Assert.AreEqual (0, webHttp.Behaviors.Count, "webHttp.Behaviors.Count #1");
\r
71 Assert.AreEqual (0, basicHttp.Behaviors.Count, "basicHttp.Behaviors.Count #1");
\r
75 Assert.AreEqual (1, webHttp.Behaviors.Count, "webHttp.Behaviors.Count #2");
\r
76 Assert.AreEqual (typeof (WebHttpBehavior), webHttp.Behaviors [0].GetType (), "behavior type");
\r
77 Assert.AreEqual (0, basicHttp.Behaviors.Count, "basicHttp.Behaviors.Count #2");
\r
83 [Category("NotWorking")]
\r
84 public void WebHttpBehaviorTest2 () {
\r
86 var host = new WebServiceHost (typeof (MyService), new Uri ("http://localhost:8080/"));
\r
87 ServiceEndpoint webHttp = host.AddServiceEndpoint ("MonoTests.System.ServiceModel.Web.WebServiceHostTest+MyService", new WebHttpBinding (), "WebHttpBinding");
\r
88 MyWebHttpBehavior behavior = new MyWebHttpBehavior ();
\r
89 behavior.ApplyDispatchBehaviorBegin += delegate {
\r
90 Assert.AreEqual (typeof (EndpointAddressMessageFilter), ((ChannelDispatcher) host.ChannelDispatchers [0]).Endpoints [0].AddressFilter.GetType (), "AddressFilter.GetType #1");
\r
91 Assert.AreEqual (typeof (ActionMessageFilter), ((ChannelDispatcher) host.ChannelDispatchers [0]).Endpoints [0].ContractFilter.GetType (), "ContractFilter.GetType #1");
\r
93 behavior.ApplyDispatchBehaviorEnd += delegate {
\r
94 Assert.AreEqual (typeof (PrefixEndpointAddressMessageFilter), ((ChannelDispatcher) host.ChannelDispatchers [0]).Endpoints [0].AddressFilter.GetType (), "AddressFilter.GetType #2");
\r
95 Assert.AreEqual (typeof (MatchAllMessageFilter), ((ChannelDispatcher) host.ChannelDispatchers [0]).Endpoints [0].ContractFilter.GetType (), "ContractFilter.GetType #2");
\r
97 webHttp.Behaviors.Add (behavior);
\r
104 public void ServiceBaseUriTest () {
\r
106 var host = new WebServiceHost (typeof (MyService), new Uri ("http://localhost:8080/"));
\r
107 Assert.AreEqual (0, host.Description.Endpoints.Count, "no endpoints yet");
\r
109 Assert.AreEqual (1, host.Description.Endpoints.Count, "default endpoint after open");
\r
113 class MyWebHttpBehavior : WebHttpBehavior
\r
115 public event EventHandler ApplyDispatchBehaviorBegin;
\r
116 public event EventHandler ApplyDispatchBehaviorEnd;
\r
118 public override void ApplyDispatchBehavior (ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) {
\r
119 if (ApplyDispatchBehaviorBegin != null)
\r
120 ApplyDispatchBehaviorBegin (this, EventArgs.Empty);
\r
121 base.ApplyDispatchBehavior (endpoint, endpointDispatcher);
\r
122 if (ApplyDispatchBehaviorEnd != null)
\r
123 ApplyDispatchBehaviorEnd (this, EventArgs.Empty);
\r
128 public class MyService
\r
130 [OperationContract]
\r
131 [WebGet (RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
\r
132 public string Greet (string input) {
\r
133 return "huh? " + input;
\r