【问题标题】:WCF self hosting is not workingWCF 自托管不起作用
【发布时间】:2014-05-30 14:14:59
【问题描述】:
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();
         }
    }
}

当我运行这个应用程序时,它运行良好。但是这个网址没有得到服务。请帮助我摆脱这个问题。谢谢

【问题讨论】:

  • "url is not getting with service" 您能详细说明一下,您是否收到错误消息、超时或其他什么?能否请您提供有关您如何访问该服务的详细信息。
  • 没有得到什么?相处不来?
  • 也许可以尝试在 ServiceHost 构造函数中添加一个基地址,如下所示:ServiceHost host = new ServiceHost(typeof(HelloService), new Uri("localhost:8080"))
  • 碰巧你没有运行一个运行 IIS 并捕获端口的操作系统,是吗?

标签: c# .net wcf


【解决方案1】:

尝试使用基本 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();

【讨论】:

    猜你喜欢
    • 2015-05-14
    • 2013-03-10
    • 1970-01-01
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多