Make "https" scheme only when Transport security mode is ON
authorstukselbax <stukselbax@gmail.com>
Mon, 26 Oct 2015 10:29:35 +0000 (13:29 +0300)
committerstukselbax <stukselbax@gmail.com>
Mon, 26 Oct 2015 10:29:35 +0000 (13:29 +0300)
The behavior of the WebHttpBinding in case of SecurityMode ==
WebHttpSecurityMode.TransportCredentialOnly must use the http scheme, in
order to allow authentication of the client based on the standard HTTP
headers, like WWW-Authenticate: Scheme realm="" and so on. This behavior
is the default in .net;

mcs/class/System.ServiceModel.Web/System.ServiceModel/WebHttpBinding.cs
mcs/class/System.ServiceModel.Web/Test/System.ServiceModel/WebHttpBindingTest.cs

index fc8a065f5ae483a7794091ba8193f288ee982056..8eee88bb876ad8387abadae15f001784359e2f8f 100644 (file)
@@ -158,7 +158,7 @@ namespace System.ServiceModel
                }
 
                public override string Scheme {
-                       get { return Security.Mode != WebHttpSecurityMode.None ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
+                       get { return Security.Mode == WebHttpSecurityMode.Transport ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; }
                }
 
                public WebHttpSecurity Security {
index 1c0c0077ce8073d0cce0ac4d2406772a11d00c9b..b4a016a26f440ef6aec434633fbd37f8bd8a49d0 100644 (file)
@@ -32,5 +32,15 @@ namespace MonoTests.System.ServiceModel
                        Assert.AreEqual (typeof (WebMessageEncodingBindingElement), bc [0].GetType (), "#2");
                        Assert.AreEqual (typeof (HttpTransportBindingElement), bc [1].GetType (), "#3");
                }
+        
+        [Test]
+        public void DefaultSchemeBasedOnSecurityMode ()
+        {
+            WebHttpBinding b = new WebHttpBinding(WebHttpSecurityMode.TransportCredentialOnly);
+            Assert.AreEqual("http", b.Scheme, "#1");
+
+            b = new WebHttpBinding(WebHttpSecurityMode.Transport);
+            Assert.AreEqual("https", b.Scheme, "#2");
+        }
        }
 }