Created
October 12, 2011 09:58
-
-
Save pmhsfelix/1280789 to your computer and use it in GitHub Desktop.
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
namespace MultipleServicesForTheSameBinding | |
{ | |
[ServiceContract] | |
interface IAServiceContract | |
{ | |
[OperationContract] | |
string Get(); | |
} | |
class AService : IAServiceContract{ | |
public string Get() | |
{ | |
return "AService"; | |
} | |
} | |
[ServiceContract] | |
interface IAnotherServiceContract | |
{ | |
[OperationContract] | |
string Get(); | |
} | |
class AnotherService : IAnotherServiceContract | |
{ | |
public string Get() | |
{ | |
return "AnotherService"; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var h1 = new ServiceHost(typeof (AService)); | |
var h2 = new ServiceHost(typeof(AnotherService)); | |
h1.AddServiceEndpoint(typeof (IAServiceContract), | |
new BasicHttpBinding(),"http://localhost:8080/base1"); | |
h2.AddServiceEndpoint(typeof(IAnotherServiceContract), | |
new BasicHttpBinding(), "http://localhost:8080/base2"); | |
h1.Open(); | |
h2.Open(); | |
Console.WriteLine("Both hosts are opened"); | |
var cf1 = new ChannelFactory<IAServiceContract>(new BasicHttpBinding(), | |
"http://localhost:8080/base1"); | |
Console.WriteLine(cf1.CreateChannel().Get()); | |
var cf2 = new ChannelFactory<IAnotherServiceContract>(new BasicHttpBinding(), | |
"http://localhost:8080/base2"); | |
Console.WriteLine(cf2.CreateChannel().Get()); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment