private static Binding GetBinding() { var issuerBinding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential); issuerBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; issuerBinding.Security.Message.EstablishSecurityContext = false; var endpointAddress = new EndpointAddress("https://issueraddress/adfs/services/trust/13/usernamemixed"); var tokenParameters = WSTrustTokenParameters.CreateWS2007FederationTokenParameters(issuerBinding, endpointAddress); // This works around https://github.com/dotnet/wcf/issues/4425 until an updated // System.ServiceModel.Federation package is published. tokenParameters.KeyType = System.IdentityModel.Tokens.SecurityKeyType.SymmetricKey; return(new WSFederationHttpBinding(tokenParameters)); }
public static void WS2007TrustTokeParameters_WSStaticHelper() { Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; EndpointAddress issuerAddress = null; EndpointAddress serviceEndpointAddress = null; string tokenTargetAddress = null; string testString = "Hello"; ChannelFactory <IWcfService> factory = null; IWcfService serviceProxy = null; try { // *** SETUP *** \\ issuerAddress = new EndpointAddress(new Uri(Endpoints.WSFederationAuthorityLocalSTS + "wsHttp/wstrust13")); tokenTargetAddress = Endpoints.Https_SecModeTransWithMessCred_ClientCredTypeIssuedTokenSaml2 + "wsHttp/wstrust13"; serviceEndpointAddress = new EndpointAddress(new Uri(tokenTargetAddress)); var issuerBinding = new WSHttpBinding(SecurityMode.Transport); issuerBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; WSFederationHttpBinding federationBinding = new WSFederationHttpBinding(WSTrustTokenParameters.CreateWS2007FederationTokenParameters(issuerBinding, issuerAddress)); federationBinding.Security.Message.EstablishSecurityContext = false; factory = new ChannelFactory <IWcfService>(federationBinding, serviceEndpointAddress); factory.Credentials.UserName.UserName = "******"; // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Not a real secret")] factory.Credentials.UserName.Password = "******"; serviceProxy = factory.CreateChannel(); // *** EXECUTE *** \\ string result = serviceProxy.Echo(testString); // *** VALIDATE *** \\ Assert.Equal(testString, result); // *** CLEANUP *** \\ ((ICommunicationObject)serviceProxy).Close(); factory.Close(); } finally { // *** ENSURE CLEANUP *** \\ ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }