我正在尝试将以前在任务栏中的 .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();
}
}
但是,应该接收此服务的客户端应用程序(在服务被包装到控制台应用程序之前曾经工作)现在崩溃并出现错误:
在http://localhost:5000/CheckoutService.svc上没有可以接受消息的端点侦听。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。
app.config 中此客户端的端点配置为:
<endpoint
address="http://localhost:5000/CheckoutService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICheckoutService"
contract="CheckoutServiceServer.ICheckoutService" name="BasicHttpBinding_ICheckoutService" />
我想也许我.config
在托管 WCF 服务的控制台项目中缺少某种形式的文件,但我可能错了!