rak*_*los 7 c# console wcf web-services visual-studio
我在控制台应用程序中创建一个简单的Web服务.(PersonService)这是我的Program.cs如下
我试图将服务引用添加到另一个控制台应用程序(PersonClient)我该怎么做?我尝试通过右键单击添加它,添加服务引用,指向引用等...但它不会工作.
[DataContract]
public class Person
{
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }
}
[ServiceContract]
public interface IPersonLookup
{
[OperationContract]
Person GetPerson(int identifier);
}
public class PersonService : IPersonLookup
{
public PersonService()
{
}
public Person GetPerson(int identifier)
{
Person p = new Person();
p.FirstName="Jane";
p.LastName="Doe";
return p;
}
}
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(PersonService)))
{
WSHttpBinding binding = new WSHttpBinding();
host.AddServiceEndpoint(typeof(IPersonLookup), binding, "http://localhost:9090/PersonService");
host.Open();
Console.WriteLine("Listening....");
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 12
解:
| 归档时间: |
|
| 查看次数: |
23806 次 |
| 最近记录: |