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.

CHAPTER 6 ■ MANAGING WCF SERVICES 185ramrameshreddy.blog.compublic string StopMonitoring(string ticker){lock (this){// End the monitoring process here.return "Monitoring has finished for " +ticker;}}}//end of TradeService Class}//end of NamespaceIn this code, you have implemented the ITradeMonitor interface in TradeService.cs andwill display a message and the ticker name as the functionality of these methods. Traditionally,developers utilized this mechanism to create log files, implement auditing, and enable traceinformation. The WCF service is operational now, so let’s try to host it (refer to Chapter 5 fordetailed descriptions on various hosting options in WCF).As mentioned, we will show how to utilize the self-hosting option for this example. Therefore,create a new console project (select File ➤ Add ➤ New Project ➤ Console Application)called TradeServiceHost, and add it to the WCFManagement solution. Rename the program.csfile to host.cs. You will need to add a reference to the ExchangeService project and add a referenceto the System.ServiceModel namespace. Listing 6-3 illustrates the code for host.cs.Listing 6-3. Self-Hosting Codeusing System;using System.Collections.Generic;using System.ServiceModel;using System.Text;namespace ExchangeService{public class Program{public static void Main(string[] args){using (ServiceHost host = new ServiceHost(typeof(TradeService),new Uri[] { new Uri("http://localhost:8000/") })){host.Open();Console.WriteLine("The WCF Management tradingservice is available.");Console.ReadKey();}}}}ramrameshreddyramrameshreddy

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

Saved successfully!

Ooh no, something went wrong!