我刚刚使用this MSDN tutorial创建了一个WCF服务。
现在我想启动我的服务OUTSIDE visual studio并让各种客户端使用它。
但是当我转到命令行并执行此文件../bin/Debug/testService.exe时,我得到一个例外:“输入格式错误”。
发布服务并启动已发布的.exe文件时出现同样的错误。
我在这里缺少什么?我是否需要发送Visual Studio发送的某些参数才能使其运行?
如何在Visual Studio外部运行我的WCF服务?
答案 0 :(得分:2)
如果没有看到您的代码和配置文件,很难弄清楚为什么会出现这个问题,但是一开始正确设置WCF服务可能会有点棘手。
我建议您查看endpoint.TV screencasts on WCF,特别是self hosting WCF services截屏视频。
它们很容易理解,并且会解释得足以让您入门。
答案 1 :(得分:0)
对我来说,向人们展示如何启动和运行WCF应用程序的最简单方法就是手动创建,避免使用VS2008内置工具。这是一个很好的教程,可以告诉你该做什么:
WCF the Manual Way - the Right Way
我写了一篇文章,在我的博客文章中稍微扩展了一篇文章。我包括sourcefiles以及截屏视频。你可以在这里找到它:
此外,在Michele Bustamante的Learning WCF中可以找到一系列优秀的教程。它有点陈旧,专注于.NET 3.0,但大多数示例仍然有效,她在她的博客上更新了她的来源。
答案 2 :(得分:0)
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