日期:2014-05-20 浏览次数:20777 次
[ServiceContract]
public interface IService1
{
[OperationContract]
void Init(string type);
[OperationContract]
string GetData(int value);
}
public class Service1 : IService1
{
private ITest test = null;
public void Init(string type)
{
switch (type)
{
case "A":
test = new TestA();
break;
case "B":
test = new TestB();
break;
case "C":
test = new TestC();
break;
default:
test = null;
break;
}
}
public string GetData(int value)
{
if (test == null)
{
return (value).ToString();
}
return test.GetData(value);
}
}
public interface ITest
{
string GetData(int value);
}
public class TestA : ITest
{
public string GetData(int value)
{
return (value).ToString() + "\tA";
}
}
public class TestB : ITest
{
public string GetData(int value)
{
return (value).ToString() + "\tB";
}
}
public class TestC : ITest
{
public string GetData(int value)
{
return (value).ToString() + "\tC";
}
}
class Program
{
static void Main(string[] args)
{
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
client.Init("B");
Console.WriteLine(client.GetData(5));
}
}