我在调用 WCF 服务时收到“未找到端点”。它是控制台应用程序中的自托管服务。
这是我的代码:
IService.cs
namespace ClassLibrary
{
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet]
string GetMessage(string inputMessage);
[OperationContract]
[WebInvoke]
string PostMessage(string inputMessage);
}
}
服务.cs
namespace ClassLibrary
{
public class Service : IService
{
public string GetMessage(string inputMessage)
{
return "En GetMessage llega " + inputMessage;
}
public string PostMessage(string inputMessage)
{
return "En PostMessage llega " + inputMessage;
}
}
}
和控制台应用程序:
namespace ConsoleHost
{
class Program
{
static void Main(string[] args)
{
WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000"));
ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
ServiceDebugBehavior db = host.Description.Behaviors.Find<ServiceDebugBehavior>();
db.HttpHelpPageEnabled = false;
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.Open();
Console.WriteLine("Service is up and running");
Console.WriteLine("Press enter to quit ");
Console.ReadLine();
host.Close();
}
}
}
没有配置文件,因为它都在代码中。
以及对服务的调用:
http://localhost:8000/
任何帮助将非常感激。谢谢!