11.07.2015 Views

y - Net Developer

y - Net Developer

y - Net Developer

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

amrameshreddy.blog.com218 CHAPTER 7 ■ IMPLEMENTING WCF SECURITYramrameshreddy.blog.comThe most significant code changes will be in the ExchangeService class. You will modifythe code to reflect the claims the client will make to gain access to the service. Here are thesteps:1. Open Visual Studio 2005 (select Start ➤ Programs ➤ MS Visual Studio 2005 ➤ MicrosoftVisual Studio 2005).2. Create a blank solution in Visual Studio 2005 (select File ➤ New ➤ Project).3. Select Visual Studio Solutions ➤ Other Project Types, and choose Blank Solution. Namethis solution WCFSecurity, and point to your preferred directory (C:\PracticalWcf\Chapter07 in this example).4. Add the ExchangeService project from Chapter 6 (right-click the WCFSecurity solution,and select Add ➤ Existing Project). The next step is to make some changes to theTradeSecurity code. As shown in Listing 7-1, modify the code to gain access to claiminformation. The rest of the class is identical to the Chapter 6 code.Listing 7-1. Adding Claim Access Code to the ExchangeService Classpublic double TradeSecurity(string ticker, int quantity){Console.WriteLine("Claim made at " + System.DateTime.Now.TimeOfDay);System.ServiceModel.OperationContext opx;opx = OperationContext.Current;if (opx != null){System.IdentityModel.Policy.AuthorizationContext ctx =opx.ServiceSecurityContext.AuthorizationContext;foreach (System.IdentityModel.Claims.ClaimSet cs in ctx.ClaimSets){Console.WriteLine("Claim Issued by : " + cs.Issuer);foreach (System.IdentityModel.Claims.Claim claim in cs){Console.WriteLine("Claim Type - " + claim.ClaimType);Console.WriteLine("Claim Resource name - " +claim.Resource);Console.WriteLine("Claim Right - " + claim.Right);}}}if (quantity < 1)throw new ArgumentException("Invalid quantity", "quantity");switch (ticker.ToLower()){case "ibm":return quantity * IBM_Price;ramrameshreddyramrameshreddy

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!