我有一个托管在控制台应用程序上的 WCF 服务,代码是:
public interface ITestService
{
[OperationContract]
void SetField(string data);
[OperationContract]
string GetField();
}
public class TestService : ITestService
{
private string myData;
public string GetField()
{
retrun myData;
}
public void SetField(string data)
{
myData = data;
}
}
然后我将它托管在控制台应用程序上:
ServiceHost host = new ServiceHost(typeof(TestService));
host.Open();
Console.WriteLine("Test Service Host");
Console.WriteLine("Service Started!");
foreach (Uri address in host.BaseAddresses)
{
Console.WriteLine("Listening on " + address);
}
Console.WriteLine("Press any key to close the host...");
Console.ReadLine();
host.Close();
我启动了控制台主机,然后在另一个控制台应用程序中,我引用了该服务并使用了它:
TestService client = new TestService();
client.SetField("test");
Console.WriteLine( client.GetField() );
这个 print nothing 意味着该字段仍然为空
这项服务有什么问题?