I'm new to WCF and C#.
I'm trying to create a WCF Service with 1 Interface (IA) with 1 method (Do) which has 2 implementations (A1 & A2).
A silly example:
IA.cs:
namespace IA_NS
{
[ServiceContract]
public interface IA
{
[OperationContract]
int Do(B b);
}
[DataContract]
public class B
{
[DataMember]
public string b1 { get; set; }
}
}
A1.cs:
namespace A1_NS
{
public class A1 : IA
{
public int Do(B b) {...}
}
}
A2.cs:
namespace A2_NS
{
public class A2 : IA
{
public int Do(B b) {...}
}
}
My Self-Hosting-Console, where I host both services:
class Program
{
static void Main(string[] args)
{
ServiceHost hostA1 = new ServiceHost(typeof(A1_NS.A1));
hostA1.Open();
ServiceHost hostA2 = new ServiceHost(typeof(A2_NS.A2));
hostA2.Open();
Console.WriteLine("Hit any key to exit...");
Console.ReadLine();
hostA1.Close();
hostA2.Close();
}
}
I want my WCF Client to be able to call both classes:
Client.cs:
namespace Client_NS
{
class Program
{
static void Main(string[] args)
{
B myB = new B();
A1 a1 = new A1();
A2 a2 = new A2();
A1.Do(myB);
A2.Do(myB);
}
}
}
No luck ;-(
I tried putting 2 elements in my WCF-Service app.config:
<service name="A1_NS.A1" >
<endpoint address="http://localhost/A1"
contract="IA_NS.IA" />
</service>
<service name="A2_NS.A2" >
<endpoint address="http://localhost/A2"
contract="IA_NS.IA" />
</service>
When running the debugger - the debugging app (WCF Service Host) lets me test the Do() method of both classes.
I can't get my Client to do it. I added Service References for both services. Is it the Client app.config or am I misunderstanding something?