Skip to content

Instantly share code, notes, and snippets.

@pmhsfelix
Created October 12, 2011 09:58
Show Gist options
  • Save pmhsfelix/1280789 to your computer and use it in GitHub Desktop.
Save pmhsfelix/1280789 to your computer and use it in GitHub Desktop.
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