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.com390 CHAPTER 12 ■ DEVELOPING PEER-TO-PEER APPLICATIONS WITH WCFramrameshreddy.blog.comBinding ConfigurationThe updated binding configuration used both by the host and by the client in this exampleis called BindingSecurePassword. The main difference between this and the previous exampleis the addition of the security details, as shown in Listing 12-10. As you can see, we have thesecurity mode set to Transport and the type to Password.Listing 12-10. Secure Binding ConfigurationMain ApplicationThe main application is the same as shown in Figure 12-5. The only difference between thisand the earlier example is the addition of a new member variable to hold the password, whichis read from the App.config file.■Note It is not recommended to save the password in App.config in clear text because then anyone canopen it and read the password. It is recommended to save the password in an encrypted storage or possiblyaccept the password from the user at runtime. To hold the password in memory, use the SecureStringclass, which was introduced in .NET 2.0.Listing 12-11 shows the updated member variable used by the solution. The channel is ofthe type IQuickReturnTraderChat, which as you know is the contract implemented by theservice. The members host and channelFactory are the service host and the channel factory,respectively. And the two string variables store the user and password that are read from theApp.config file using ConfigurationManager.AppSettings in the constructor for the class Main.Listing 12-11. Member Variable ListIQuickReturnTraderChat channel;ServiceHost host = null;ChannelFactory channelFactory = null;string userID = "";string password = null;ramrameshreddyramrameshreddyThe StartService method in the class Main has been updated slightly, as shown inListing 12-12. This now uses a different endpoint configuration file and sets the password for boththe host and the channel. The StopService method remains the same as earlier and is not listed

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

Saved successfully!

Ooh no, something went wrong!