自托管wcf控制台打印数据

时间:2015-04-07 11:09:02

标签: c# wcf

我正在使用以下控制台应用程序:

static void Main(string[] args)
    {
        using (ServiceHost host = new ServiceHost(typeof(SampleServiceNamespace.SampleService)))
        {
            host.Open();

            Console.WriteLine("Service up and running at:");
            foreach (var ea in host.Description.Endpoints)
            {
                Console.WriteLine(ea.Address);
            }

            //

            Console.ReadLine();
            host.Close();
        }
    }

wcf库实现了以下内容:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
Person aPerson = new Person();
    public string GreetMe(Person person)
    {
        return string.Format("Greetings from Sample service Mr. {0}", person.Name);

    }

    public void setPersonName(string aName) //Output this aPerson.Name to the screen
    {
        aPerson.Name = aName;
    }

界面:

[ServiceContract]
public interface ISampleService
{
    [OperationContract]
    string GreetMe(Person person);
    [OperationContract]
    void setPersonName(string aName);
}

[DataContract]
public class Person
{
    [DataMember]
    public string Name { get; set; }
}

我想要实现的是将数据打印到屏幕上。例如,每次我从客户端发送一个名称字符串,我想在屏幕上输出。

0 个答案:

没有答案