Created
December 28, 2011 08:50
-
-
Save JoanComasFdz/1527159 to your computer and use it in GitHub Desktop.
Host wcf service in console app basic code (using dual tcp to allow callbacks)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ServiceModel; | |
using <YOUR_SERVICE_NAMESPACE>; | |
namespace Host_Service_with_callbacks_via_tcp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
ServiceHost host = null; | |
try | |
{ | |
// Create server, it will use the settings | |
// in App.config file. | |
host = new ServiceHost(typeof(Service1)); | |
// Open it | |
host.Open(); | |
// Wait to exit | |
Console.WriteLine(string.Format("Service running @ {0}", host.Description.Endpoints[0].Address)); | |
Console.WriteLine("Press [ENTER] to exit."); | |
Console.ReadLine(); | |
} | |
catch (Exception ex) | |
{ | |
// Oups | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.WriteLine(string.Format("/!\\ Error:\r\n{0}:\r\n{1}", ex.GetType(), ex.Message)); | |
Console.ReadLine(); | |
} | |
finally | |
{ | |
// Clean memory | |
if (host != null) | |
((IDisposable)host).Dispose(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment