diff --git a/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest.ConnectionGroupName Example/CPP/source.cpp b/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest.ConnectionGroupName Example/CPP/source.cpp deleted file mode 100644 index a1ed8be7efe..00000000000 --- a/snippets/cpp/VS_Snippets_Remoting/Classic HttpWebRequest.ConnectionGroupName Example/CPP/source.cpp +++ /dev/null @@ -1,36 +0,0 @@ - - -#using -#using - -using namespace System; -using namespace System::Net; -using namespace System::Web; -using namespace System::Web::UI; -using namespace System::Security::Cryptography; -using namespace System::Text; -int main() -{ - // - // Create a secure group name. - // This example uses the SHA1 algorithm. - // Due to collision problems with SHA1, Microsoft recommends SHA256 or better. - SHA1Managed^ Sha1 = gcnew SHA1Managed; - array^updHash = Sha1->ComputeHash( Encoding::UTF8->GetBytes( "usernamepassworddomain" ) ); - String^ secureGroupName = Encoding::Default->GetString( updHash ); - - // Create a request for a specific URL. - WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" ); - - // Set the authentication credentials for the request. - myWebRequest->Credentials = gcnew NetworkCredential( "username","password","domain" ); - myWebRequest->ConnectionGroupName = secureGroupName; - - // Get the response. - WebResponse^ myWebResponse = myWebRequest->GetResponse(); - - // Insert the code that uses myWebResponse here. - // Close the response. - myWebResponse->Close(); - // -} diff --git a/snippets/csharp/System.Net/WebRequest/PreAuthenticate/Project.csproj b/snippets/csharp/System.Net/WebRequest/PreAuthenticate/Project.csproj deleted file mode 100644 index c02dc5044e7..00000000000 --- a/snippets/csharp/System.Net/WebRequest/PreAuthenticate/Project.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Library - net6.0 - - - \ No newline at end of file diff --git a/snippets/csharp/System.Net/WebRequest/PreAuthenticate/webrequest_preauthenticate.cs b/snippets/csharp/System.Net/WebRequest/PreAuthenticate/webrequest_preauthenticate.cs deleted file mode 100644 index 82fe68271b1..00000000000 --- a/snippets/csharp/System.Net/WebRequest/PreAuthenticate/webrequest_preauthenticate.cs +++ /dev/null @@ -1,89 +0,0 @@ -/*System.Net.WebRequest.PreAuthenticate,System.Net.WebRequest.Credentials - This program demonstrates the 'PreAuthenticate' and 'NetworkCredential' properties of the WebRequest Class. -The PreAuthenticate Property has a default value set to False. -This is set to True and new NetwrokCredential object is created with UserName and Password. -This NetworkCredential Object associated to the WebRequest Object to be able to authenticate the requested Uri -To check the validity of this program, please try with some authenticated sites with appropriate credentials*/ - -using System; -using System.IO; -using System.Net; -using System.Text; - -class WebRequest_Preauthenticate -{ - static void Main(string[] args) - { - if (args.Length < 1) - { - Console.WriteLine("\nPlease type the url which requires authentication as command line parameter"); - Console.WriteLine("Example:WebRequest_PreAuthenticate http://www.microsoft.com"); - } - else - { - GetPage(args[0]); - } - Console.WriteLine("\nPress any key to continue..."); - Console.ReadLine(); - return; - } - public static void GetPage(string url) - { - try - { -// -// - - // Create a new webrequest to the mentioned URL. - WebRequest myWebRequest=WebRequest.Create(url); - - // Set 'Preauthenticate' property to true. Credentials will be sent with the request. - myWebRequest.PreAuthenticate=true; - - Console.WriteLine("\nPlease enter your credentials for the requested Url"); - Console.WriteLine("UserName"); - string UserName=Console.ReadLine(); - Console.WriteLine("Password"); - string Password=Console.ReadLine(); - - // Create a New 'NetworkCredential' object. - NetworkCredential networkCredential=new NetworkCredential(UserName,Password); - - // Associate the 'NetworkCredential' object with the 'WebRequest' object. - myWebRequest.Credentials=networkCredential; - - // Assign the response object of 'WebRequest' to a 'WebResponse' variable. - WebResponse myWebResponse=myWebRequest.GetResponse(); - -// -// - // Read the 'Response' into a Stream object and then print to the console. - Stream streamResponse=myWebResponse.GetResponseStream(); - StreamReader streamRead = new StreamReader( streamResponse ); - Char[] readBuff = new Char[256]; - int count = streamRead.Read( readBuff, 0, 256 ); - Console.WriteLine("\nThe contents of the Html page of the requested Uri are : "); - while (count > 0) - { - String outputData = new String(readBuff, 0, count); - Console.Write(outputData); - count = streamRead.Read(readBuff, 0, 256); - } - // Close the Stream object. - streamResponse.Close(); - streamRead.Close(); - // Release the HttpWebResponse Resource. - myWebResponse.Close(); - } - catch(WebException e) - { - Console.WriteLine("\nWebException is raised. "); - Console.WriteLine("\nMessage:{0} ",e.Message); - } - catch(Exception e) - { - Console.WriteLine("\nException is raised. "); - Console.WriteLine("\nMessage:{0} ",e.Message); - } - } -} diff --git a/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/Project.csproj b/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/Project.csproj new file mode 100644 index 00000000000..543b3a6c115 --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/Project.csproj @@ -0,0 +1,15 @@ + + + + Library + net481 + 11 + + + + + + + + + diff --git a/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/makefile b/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/makefile deleted file mode 100644 index 2a0ebf3c0a6..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: service.exe - -service.exe: service.cs - csc /t:exe *.cs /r:System.ServiceModel.dll,System.Runtime.Serialization.dll,System.IdentityModel.dll /lib:c:\whidbey\assemblies diff --git a/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/service.cs b/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/service.cs index 0e9c0997326..4ee45f4127a 100644 --- a/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/service.cs +++ b/snippets/csharp/VS_Snippets_CFX/c_claimset/cs/service.cs @@ -4,22 +4,17 @@ using System; using System.Collections.Generic; using System.Configuration; - using System.IdentityModel.Claims; using System.IdentityModel.Policy; -using System.IdentityModel.Tokens; using System.IdentityModel.Selectors; - using System.Security.Principal; using System.ServiceModel; -using System.ServiceModel.Description; -using System.ServiceModel.Security; namespace Microsoft.ServiceModel.Samples { // Define a service contract. - [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")] + [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")] public interface ICalculator { [OperationContract] @@ -34,8 +29,8 @@ public interface ICalculator // Service class that implements the service contract. // Added code to write output to the console window. - [ServiceBehavior(IncludeExceptionDetailInFaults=true)] - + [ServiceBehavior(IncludeExceptionDetailInFaults = true)] + public class CalculatorService : ICalculator { public double Add(double n1, double n2) @@ -43,7 +38,7 @@ public double Add(double n1, double n2) double result = n1 + n2; Console.WriteLine("Received Add({0},{1})", n1, n2); Console.WriteLine("Return: {0}", result); - return result; + return result; } public double Subtract(double n1, double n2) @@ -74,7 +69,7 @@ public double Divide(double n1, double n2) public class MyServiceAuthorizationManager : ServiceAuthorizationManager { - protected override bool CheckAccessCore(OperationContext operationContext) + protected override bool CheckAccessCore(OperationContext operationContext) { // Extract the action URI from the OperationContext. Match this against the claims // in the AuthorizationContext. @@ -83,7 +78,7 @@ protected override bool CheckAccessCore(OperationContext operationContext) Console.WriteLine("action: {0}", action); // Iterate through the various claim sets in the AuthorizationContext. - foreach(ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets) + foreach (ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets) { // Examine only those claim sets issued by System. if (cs.Issuer == ClaimSet.System) @@ -109,13 +104,14 @@ protected override bool CheckAccessCore(OperationContext operationContext) } } // + public class MyAuthorizationPolicy : IAuthorizationPolicy { string id; public MyAuthorizationPolicy() { - id = Guid.NewGuid().ToString(); + id = Guid.NewGuid().ToString(); } // @@ -158,7 +154,7 @@ public bool Evaluate(EvaluationContext evaluationContext, ref object state) } // Add claims to the evaluation context. - evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer,claims)); + evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer, claims)); // Record that the claims have been added. customstate.ClaimsAdded = true; @@ -193,14 +189,14 @@ private IEnumerable GetAllowedOpList(string username) if (username == "test1") { - ret.Add ( "http://Microsoft.ServiceModel.Samples/ICalculator/Add"); - ret.Add ("http://Microsoft.ServiceModel.Samples/ICalculator/Multiply"); + ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Add"); + ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Multiply"); ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract"); } else if (username == "test2") { - ret.Add ( "http://Microsoft.ServiceModel.Samples/ICalculator/Add"); - ret.Add ("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract"); + ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Add"); + ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract"); } return ret; } @@ -215,28 +211,19 @@ public CustomAuthState() bClaimsAdded = false; } - public bool ClaimsAdded { get { return bClaimsAdded; } - set { bClaimsAdded = value; } } + public bool ClaimsAdded + { + get { return bClaimsAdded; } + set { bClaimsAdded = value; } + } } } public class MyCustomUserNameValidator : UserNamePasswordValidator { - // This method validates users. It allows two users, test1 and test2 - // with passwords 1tset and 2tset respectively. - // This code is for illustration purposes only and - // MUST NOT be used in a production environment because it is NOT secure. public override void Validate(string userName, string password) { - if (null == userName || null == password) - { - throw new ArgumentNullException(); - } - - if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset")) - { - throw new SecurityTokenException("Unknown Username or Password"); - } + throw new NotImplementedException(); } } @@ -244,17 +231,17 @@ public override void Validate(string userName, string password) public static void Main() { // Get the base address from appsettings in configuration. - Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]); + Uri baseAddress = new(ConfigurationManager.AppSettings["baseAddress"]); // Create a ServiceHost for the CalculatorService type and provide the base address. using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress)) { // Open the ServiceHostBase to create listeners and start listening for messages. serviceHost.Open(); - + // The service can now be accessed. Console.WriteLine("The service is ready."); - Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name); + Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name); Console.WriteLine("Press to terminate service."); Console.WriteLine(); Console.ReadLine(); diff --git a/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/Project.csproj b/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/Project.csproj new file mode 100644 index 00000000000..f59f82c3d22 --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/Project.csproj @@ -0,0 +1,15 @@ + + + + Library + net481 + 11 + + + + + + + + + diff --git a/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/makefile b/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/makefile deleted file mode 100644 index 2a0ebf3c0a6..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: service.exe - -service.exe: service.cs - csc /t:exe *.cs /r:System.ServiceModel.dll,System.Runtime.Serialization.dll,System.IdentityModel.dll /lib:c:\whidbey\assemblies diff --git a/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/service.cs b/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/service.cs index cd522e1384e..3db20bd7174 100644 --- a/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/service.cs +++ b/snippets/csharp/VS_Snippets_CFX/c_iauthorizationpolicy/cs/service.cs @@ -7,19 +7,16 @@ using System.IdentityModel.Claims; using System.IdentityModel.Policy; -using System.IdentityModel.Tokens; using System.IdentityModel.Selectors; using System.Security.Principal; using System.ServiceModel; -using System.ServiceModel.Description; -using System.ServiceModel.Security; namespace Microsoft.ServiceModel.Samples { // Define a service contract. - [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")] + [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")] public interface ICalculator { [OperationContract] @@ -34,8 +31,8 @@ public interface ICalculator // Service class that implements the service contract. // Added code to write output to the console window. - [ServiceBehavior(IncludeExceptionDetailInFaults=true)] - + [ServiceBehavior(IncludeExceptionDetailInFaults = true)] + public class CalculatorService : ICalculator { public double Add(double n1, double n2) @@ -43,7 +40,7 @@ public double Add(double n1, double n2) double result = n1 + n2; Console.WriteLine("Received Add({0},{1})", n1, n2); Console.WriteLine("Return: {0}", result); - return result; + return result; } public double Subtract(double n1, double n2) @@ -83,7 +80,7 @@ protected override bool CheckAccessCore(OperationContext operationContext) // // Iterate through the various claim sets in the AuthorizationContext. - foreach(ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets) + foreach (ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets) { // Examine only those claim sets issued by System. if (cs.Issuer == ClaimSet.System) @@ -114,7 +111,7 @@ public class MyAuthorizationPolicy : IAuthorizationPolicy public MyAuthorizationPolicy() { - id = Guid.NewGuid().ToString(); + id = Guid.NewGuid().ToString(); } // @@ -156,7 +153,7 @@ public bool Evaluate(EvaluationContext evaluationContext, ref object state) } // Add claims to the evaluation context. - evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer,claims)); + evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer, claims)); // Record that claims have been added. customstate.ClaimsAdded = true; @@ -192,14 +189,14 @@ private IEnumerable GetAllowedOpList(string username) if (username == "test1") { - ret.Add ( "http://Microsoft.ServiceModel.Samples/ICalculator/Add"); - ret.Add ("http://Microsoft.ServiceModel.Samples/ICalculator/Multiply"); + ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Add"); + ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Multiply"); ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract"); } else if (username == "test2") { - ret.Add ( "http://Microsoft.ServiceModel.Samples/ICalculator/Add"); - ret.Add ("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract"); + ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Add"); + ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract"); } return ret; } @@ -214,29 +211,20 @@ public CustomAuthState() bClaimsAdded = false; } - public bool ClaimsAdded { get { return bClaimsAdded; } - set { bClaimsAdded = value; } } + public bool ClaimsAdded + { + get { return bClaimsAdded; } + set { bClaimsAdded = value; } + } } } - // + public class MyCustomUserNameValidator : UserNamePasswordValidator { - // This method validates users. It allows two users, test1 and test2 - // with passwords 1tset and 2tset respectively. - // This code is for illustration purposes only and - // MUST NOT be used in a production environment because it is NOT secure. public override void Validate(string userName, string password) { - if (null == userName || null == password) - { - throw new ArgumentNullException(); - } - - if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset")) - { - throw new SecurityTokenException("Unknown Username or Password"); - } + throw new NotImplementedException(); } } @@ -251,10 +239,10 @@ public static void Main() { // Open the ServiceHostBase to create listeners and start listening for messages. serviceHost.Open(); - + // The service can now be accessed. Console.WriteLine("The service is ready."); - Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name); + Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name); Console.WriteLine("Press to terminate service."); Console.WriteLine(); Console.ReadLine(); diff --git a/snippets/csharp/VS_Snippets_CFX/c_usernamevalidator/cs/makefile b/snippets/csharp/VS_Snippets_CFX/c_usernamevalidator/cs/makefile deleted file mode 100644 index 2a0ebf3c0a6..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/c_usernamevalidator/cs/makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: service.exe - -service.exe: service.cs - csc /t:exe *.cs /r:System.ServiceModel.dll,System.Runtime.Serialization.dll,System.IdentityModel.dll /lib:c:\whidbey\assemblies diff --git a/snippets/csharp/VS_Snippets_CFX/c_usernamevalidator/cs/service.cs b/snippets/csharp/VS_Snippets_CFX/c_usernamevalidator/cs/service.cs deleted file mode 100644 index 21db5215365..00000000000 --- a/snippets/csharp/VS_Snippets_CFX/c_usernamevalidator/cs/service.cs +++ /dev/null @@ -1,266 +0,0 @@ - -// Copyright (c) Microsoft Corporation. All Rights Reserved. - -using System; -using System.Collections.Generic; -using System.Configuration; - -using System.IdentityModel.Claims; -using System.IdentityModel.Policy; -using System.IdentityModel.Tokens; -using System.IdentityModel.Selectors; - -using System.Security.Principal; - -using System.ServiceModel; -using System.ServiceModel.Description; -using System.ServiceModel.Security; - -namespace Microsoft.ServiceModel.Samples -{ - // Define a service contract. - [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")] - public interface ICalculator - { - [OperationContract] - double Add(double n1, double n2); - [OperationContract] - double Subtract(double n1, double n2); - [OperationContract] - double Multiply(double n1, double n2); - [OperationContract] - double Divide(double n1, double n2); - } - - // Service class that implements the service contract. - // Added code to write output to the console window. - [ServiceBehavior(IncludeExceptionDetailInFaults=true)] - - public class CalculatorService : ICalculator - { - public double Add(double n1, double n2) - { - double result = n1 + n2; - Console.WriteLine("Received Add({0},{1})", n1, n2); - Console.WriteLine("Return: {0}", result); - return result; - } - - public double Subtract(double n1, double n2) - { - double result = n1 - n2; - Console.WriteLine("Received Subtract({0},{1})", n1, n2); - Console.WriteLine("Return: {0}", result); - return result; - } - - public double Multiply(double n1, double n2) - { - double result = n1 * n2; - Console.WriteLine("Received Multiply({0},{1})", n1, n2); - Console.WriteLine("Return: {0}", result); - return result; - } - - public double Divide(double n1, double n2) - { - double result = n1 / n2; - Console.WriteLine("Received Divide({0},{1})", n1, n2); - Console.WriteLine("Return: {0}", result); - return result; - } - - public class MyServiceAuthorizationManager : ServiceAuthorizationManager - { - - protected override bool CheckAccessCore(OperationContext operationContext) - { - // Extract the action URI from the OperationContext. Match this against the claims - // in the AuthorizationContext. - string action = operationContext.RequestContext.RequestMessage.Headers.Action; - Console.WriteLine("action: {0}", action); - - // - // Iterate through the various claimsets in the AuthorizationContext. - foreach(ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets) - { - // Only look at claimsets issued by System. - if (cs.Issuer == ClaimSet.System) - { - // Iterate through claims of type "http://example.org/claims/allowedoperation". - foreach (Claim c in cs.FindClaims("http://example.org/claims/allowedoperation", Rights.PossessProperty)) - { - // Write the Claim resource to the console. - Console.WriteLine("resource: {0}", c.Resource.ToString()); - - // If the Claim resource matches the action URI then return true to allow access. - if (action == c.Resource.ToString()) - return true; - } - } - } - - // If we get here, return false, denying access. - return false; - } - } - - public class MyAuthorizationPolicy : IAuthorizationPolicy - { - string id; - - public MyAuthorizationPolicy() - { - id = Guid.NewGuid().ToString(); - } - - // - public bool Evaluate(EvaluationContext evaluationContext, ref object state) - { - bool bRet = false; - CustomAuthState customstate = null; - - // If state is null, then this method has not been called before so we need - // to set up our custom state. - if (state == null) - { - customstate = new CustomAuthState(); - state = customstate; - } - else - { - customstate = (CustomAuthState)state; - } - - Console.WriteLine("Inside MyAuthorizationPolicy::Evaluate"); - - // If claims have not been added yet... - if (!customstate.ClaimsAdded) - { - // Create an empty list of Claims. - IList claims = new List(); - - // Iterate through each of the claimsets in the evaluation context. - foreach (ClaimSet cs in evaluationContext.ClaimSets) - // Look for Name claims in the current claimset. - foreach (Claim c in cs.FindClaims(ClaimTypes.Name, Rights.PossessProperty)) - // Get the list of operations that the given username is allowed to call. - foreach (string s in GetAllowedOpList(c.Resource.ToString())) - { - // Add claims to the list - claims.Add(new Claim("http://example.org/claims/allowedoperation", s, Rights.PossessProperty)); - Console.WriteLine("Claim added {0}", s); - } - - // Add claims to the evaluation context. - evaluationContext.AddClaimSet(this, new DefaultClaimSet(this.Issuer,claims)); - - // Record that the claims have been added. - customstate.ClaimsAdded = true; - - // Return true, which indicates we do not need to call this method again. - bRet = true; - } - else - { - // Should never get here, but just in case... - bRet = true; - } - - return bRet; - } - // - // - public ClaimSet Issuer - { - get { return ClaimSet.System; } - } - - public string Id - { - get { return id; } - } - - // This method returns a collection of action strings that indicate the - // operations that the specified username is allowed to call. - private IEnumerable GetAllowedOpList(string username) - { - IList ret = new List(); - - if (username == "test1") - { - ret.Add ( "http://Microsoft.ServiceModel.Samples/ICalculator/Add"); - ret.Add ("http://Microsoft.ServiceModel.Samples/ICalculator/Multiply"); - ret.Add("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract"); - } - else if (username == "test2") - { - ret.Add ( "http://Microsoft.ServiceModel.Samples/ICalculator/Add"); - ret.Add ("http://Microsoft.ServiceModel.Samples/ICalculator/Subtract"); - } - return ret; - } - - // Internal class for state. - class CustomAuthState - { - bool bClaimsAdded; - - public CustomAuthState() - { - bClaimsAdded = false; - } - - public bool ClaimsAdded { get { return bClaimsAdded; } - set { bClaimsAdded = value; } } - } - } - - // - public class MyCustomUserNameValidator : UserNamePasswordValidator - { - // - // This method validates users. It allows two users, test1 and test2 - // with passwords 1tset and 2tset respectively. - // This code is for illustration purposes only and - // MUST NOT be used in a production environment because it is NOT secure. - public override void Validate(string userName, string password) - { - if (null == userName || null == password) - { - throw new ArgumentNullException(); - } - - if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset")) - { - throw new SecurityTokenException("Unknown Username or Password"); - } - } - // - } - // - // Host the service within this EXE console application. - public static void Main() - { - // Get base address from appsettings in configuration. - Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]); - - // Create a ServiceHost for the CalculatorService type and provide the base address. - using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress)) - { - // Open the ServiceHostBase to create listeners and start listening for messages. - serviceHost.Open(); - - // The service can now be accessed. - Console.WriteLine("The service is ready."); - Console.WriteLine("The service is running in the following account: {0}", WindowsIdentity.GetCurrent().Name); - Console.WriteLine("Press to terminate service."); - Console.WriteLine(); - Console.ReadLine(); - - // Close the ServiceHostBase to shutdown the service. - serviceHost.Close(); - } - } - } -} diff --git a/snippets/csharp/VS_Snippets_CFX/s_ueservicecredentials/cs/app.config b/snippets/csharp/VS_Snippets_CFX/s_ueservicecredentials/cs/app.config new file mode 100644 index 00000000000..eca069e41db --- /dev/null +++ b/snippets/csharp/VS_Snippets_CFX/s_ueservicecredentials/cs/app.config @@ -0,0 +1,3 @@ + + + diff --git a/snippets/csharp/VS_Snippets_CFX/s_ueservicecredentials/cs/cs.csproj b/snippets/csharp/VS_Snippets_CFX/s_ueservicecredentials/cs/cs.csproj index 0bce8db16c1..c69a768df41 100644 --- a/snippets/csharp/VS_Snippets_CFX/s_ueservicecredentials/cs/cs.csproj +++ b/snippets/csharp/VS_Snippets_CFX/s_ueservicecredentials/cs/cs.csproj @@ -1,4 +1,4 @@ - + Debug AnyCPU @@ -9,6 +9,13 @@ Properties CS CS + + + + + 2.0 + v4.8.1 + true @@ -18,6 +25,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -26,6 +34,7 @@ TRACE prompt 4 + false @@ -46,6 +55,9 @@ + + +