【问题标题】:How to start a WCF service outside Visual Studio?如何在 Visual Studio 之外启动 WCF 服务?
【发布时间】:2009-02-17 10:57:36
【问题描述】:

我刚刚使用this MSDN tutorial 创建了一个 WCF 服务。

  • 在 Visual Studio 中,我可以 CTRL-F5 使服务运行
  • 然后我可以启动我的控制台应用程序客户端并使用服务没有问题

现在我想在 Visual Studio 之外启动我的服务并让各种客户使用它。

但是当我进入命令行并执行这个文件 ../bin/Debug/testService.exe 时,我得到一个异常:“Input has wrong format”。

我在发布服务并启动已发布的 .exe 文件时遇到同样的错误。

我在这里缺少什么?我是否需要发送 Visual Studio 发送的某种参数以使其运行?

如何在 Visual Studio 外部运行我的 WCF 服务?

【问题讨论】:

    标签: .net wcf


    【解决方案1】:

    如果没有看到您的代码和配置文件,很难弄清楚为什么会出现此问题,但一开始正确设置 WCF 服务可能会有些棘手。

    我建议查看endpoint.TV screencasts on WCF,尤其是self hosting WCF services 截屏视频。

    它们很容易理解,并且会解释得足以让您入门。

    【讨论】:

      【解决方案2】:

      对我来说,向某人展示如何启动和运行 WCF 应用程序以便您学习的最简单方法是手动创建它,避开 VS2008 内置工具。这是一个很好的教程,告诉你该怎么做:

      WCF the Manual Way - the Right Way

      我在我的博客文章中写了一篇文章,对那篇文章进行了扩展。我包括源​​文件以及截屏视频。你可以在这里找到它:

      Manual WCF - An Extension

      此外,可以在 Michele Bustamante 的Learning WCF 中找到一系列优秀的教程。它有点过时了,专注于 .NET 3.0,但大多数示例仍然有效,她在博客上更新了她的源代码。

      【讨论】:

        【解决方案3】:
        Uri baseAddress = new Uri("http://localhost:8080/hello");
        
        // Create the ServiceHost.
        using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
        {
            // Enable metadata publishing.
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            host.Description.Behaviors.Add(smb);
        
            // Open the ServiceHost to start listening for messages. Since
            // no endpoints are explicitly configured, the runtime will create
            // one endpoint per base address for each service contract implemented
            // by the service.
            host.Open();
        
            Console.WriteLine("The service is ready at {0}", baseAddress);
            Console.WriteLine("Press <Enter> to stop the service.");
            Console.ReadLine();
        
            // Close the ServiceHost.
            host.Close();
        }
        

        http://msdn.microsoft.com/en-us/library/ms731758%28v=vs.110%29.aspx

        【讨论】:

          猜你喜欢
          • 2017-08-12
          • 1970-01-01
          • 2011-06-02
          • 2011-03-16
          • 2011-08-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-10-25
          相关资源
          最近更新 更多