WCF自托管不起作用

时间:2014-05-30 14:14:59

标签: c# .net wcf

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();
         }
    }
}

当我运行此应用程序时,它运行良好。但是这个网址并没有得到服务。请帮我解决这个问题。感谢

1 个答案:

答案 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();
相关问题