using System.ServiceModel;
namespace helloserviceDemo2
{
[ServiceContract]
interface IHelloService
{
[OperationContract]
string sayHello(string name);
}
class HelloService : IHelloService
{
public string sayHello(string name)
{
return name + " welcome";
}
}
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(HelloService));
BasicHttpBinding httpBinding = new BasicHttpBinding();
host.AddServiceEndpoint(typeof(IHelloService), httpBinding, "http://localhost:8080/helloservice");
host.Open();
Console.WriteLine("service is running now");
Console.ReadKey();
}
}
}
当我运行此应用程序时,它运行良好。但是这个网址并没有得到服务。请帮我解决这个问题。感谢
答案 0 :(得分:0)
尝试使用基本URI:
ServiceHost host = new ServiceHost(typeof(HelloService), new Uri("http://localhost:8080"));
BasicHttpBinding httpBinding = new BasicHttpBinding();
host.AddServiceEndpoint(typeof(IHelloService), httpBinding, "http://localhost:8080/helloservice");
host.Open();
Console.WriteLine("service is running now");
Console.ReadKey();