【发布时间】:2014-06-29 22:54:01
【问题描述】:
我在调用 WCF 服务时收到“未找到端点”。它是控制台应用程序中的自托管服务。
这是我的代码:
IService.cs
namespace ClassLibrary
{
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet]
string GetMessage(string inputMessage);
[OperationContract]
[WebInvoke]
string PostMessage(string inputMessage);
}
}
Service.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/
任何帮助将不胜感激。 谢谢!
【问题讨论】:
-
分享一些配置也可能会有所帮助:众所周知,WCF 错误依赖于配置。
-
你也可以分享客户端代码吗?您是否在客户端(WebHttpBinding)上使用相同的端点配置?
-
您确定您的控制台正在运行?!有时...
-
你为什么要创建一个
ServiceEndpoint ep而不用它做任何事情?这是一个未使用的变量。
标签: c# wcf endpoint self-hosting endpointnotfoundexception