c# - 在 ServiceHost 中运行的 WCF 服务(控制台应用程序)

标签 c# wcf endpoint servicehost

我正在尝试将之前在任务栏中的 .asmx 服务中运行的 WCF 服务包装到控制台应用程序中。

以下是包装 WCF 服务的代码:

class Program
{
    static void Main(string[] args)
    {
        Uri uri = new Uri("http://localhost:5000");

        using (ServiceHost host = new ServiceHost(typeof(CheckoutService), uri))
        {
                Console.WriteLine("Prepping CheckoutService server");
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);

                host.Open();

                Console.Clear();
                Console.WriteLine("CheckoutService server up and running");
                Console.WriteLine("Press Return to stop service at any point");
                Console.ReadLine();
                host.Close();
        }
    }

但是,应该接收此服务的客户端应用程序(在该服务被包装到控制台应用程序之前曾经正常工作)现在崩溃并出现错误:

There was no endpoint listening at http://localhost:5000/CheckoutService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

app.config 中此客户端的端点配置为:

<endpoint 
    address="http://localhost:5000/CheckoutService.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckoutService"
    contract="CheckoutServiceServer.ICheckoutService" name="BasicHttpBinding_ICheckoutService" />

我想我可能在托管 WCF 服务的控制台项目中缺少某种形式的 .config 文件,但我可能是错的!

最佳答案

看起来您正在关闭主机而不等待用户输入。您是否缺少Console.ReadLine()

关于c# - 在 ServiceHost 中运行的 WCF 服务(控制台应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10387119/

相关文章:

c# - .NET 中是否有独立于 UI 的 Point 结构?

c# - 从 VB6 调用的 .net 类的 Web 服务调用

java - Google App Engine 云端点在哪里?

c# - 如何转义和忽略 __debugbreak

c# - 动态创建 C# 类或对象

c# - 如何在初始化渲染器之前调用方法 [Wpf]

wcf - Entity Framework 和使用 WCF 服务

mysql - Publish Web 不包括一些依赖程序集

javascript - 我正在尝试将值从 ajax 发送到 wcf 以插入到 mysql 表中

wcf 端点相对地址