我正在尝试将之前在任务栏中的 .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/