/// <summary> /// Send message with security /// </summary> //[TestMethod] public void SendMessageWithSecurity() { string uri = String.Format("https://{0}:8080", Environment.MachineName); // Open frontend Uri listenUri = new Uri(uri); BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential); binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; MockBrokerAuthorization auth = new MockBrokerAuthorization(); MockBrokerQueue queue = new MockBrokerQueue(); queue.DirectReply = true; RequestReplyFrontEnd <IReplyChannel> target = new RequestReplyFrontEnd <IReplyChannel>(listenUri, binding, auth, queue); target.Open(); // Build channel to send request MockWCFClient client = new MockWCFClient(binding, new EndpointAddress(uri)); client.ClientCredentials.UserName.UserName = "******"; client.ClientCredentials.UserName.Password = "******"; auth.Allow = false; try { client.Calc(3); } catch (FaultException fe) { Assert.AreEqual(fe.Code.Name, "AuthenticationFailure"); } // Send request which is allowed auth.Allow = true; try { client.Calc(4); } catch (FaultException fe) { Assert.AreEqual(fe.Code.Name, "DummyReply"); } client.Close(); target.Close(); }
public void SendRequestTest() { string uri = "net.tcp://localhost:8889"; // Open frontend Uri listenUri = new Uri(uri); NetTcpBinding binding = new NetTcpBinding(SecurityMode.None); MockBrokerQueue queue = new MockBrokerQueue(); queue.DirectReply = true; DuplexFrontEnd target = new DuplexFrontEnd(listenUri, binding, null, queue, null, null); target.Open(); MockWCFClient client = new MockWCFClient(binding, new EndpointAddress(uri)); try { client.Calc(4); } catch (FaultException fe) { Assert.AreEqual(fe.Code.SubCode.Name, "DummyReply"); } target.Close(); }
public void SendRequestTestWithSecurity() { string uri = "net.tcp://localhost:8889"; // Open frontend Uri listenUri = new Uri(uri); NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport); MockBrokerQueue queue = new MockBrokerQueue(); MockBrokerAuthorization auth = new MockBrokerAuthorization(); queue.DirectReply = true; DuplexFrontEnd target = new DuplexFrontEnd(listenUri, binding, auth, queue); target.Open(); MockWCFClient client = new MockWCFClient(binding, new EndpointAddress(uri)); auth.Allow = true; try { client.Calc(4); } catch (FaultException fe) { Assert.AreEqual(fe.Code.SubCode.Name, "DummyReply"); } auth.Allow = false; try { client.Calc(4); } catch (FaultException fe) { Assert.AreEqual(fe.Code.SubCode.Name, "AuthenticationFailure"); } target.Close(); }