C# 未找到服务端点?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9864439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Service endpoint not found?
提问by G Gr
Seem to run into a service endpoint not found problem when trying to get from my service.
尝试从我的服务中获取时,似乎遇到了未找到服务端点的问题。
if I try http://localhost:8000/hello/helpI should expect to see <string>You entered help <string>but I only get the no endpoint instead? I havent touched my config files at all and I am just hosting from a console app.
如果我尝试http://localhost:8000/hello/help我应该会看到<string>You entered help <string>但我只得到 no 端点?我根本没有接触过我的配置文件,我只是从控制台应用程序托管。
Host:
主持人:
namespace Host
{
class Program
{
static void Main(string[] args)
{
WebHttpBinding binding = new WebHttpBinding();
WebServiceHost host =
new WebServiceHost(typeof(Service1));
host.AddServiceEndpoint(typeof(IService1),
binding,
"http://localhost:8000/hello");
host.Open();
Console.WriteLine("Hello world service");
Console.WriteLine("Press <RETURN> to end service");
Console.ReadLine();
}
}
}
Service1:
服务1:
namespace WcfServiceLibrary1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
IService1:
服务1:
[ServiceContract]
public interface IService1
{
[WebGet(UriTemplate = "/{value}")]
string GetData(string value);
采纳答案by Justin Pihony
Remove the / from {value} and make sure it is listed as an OperationContract. It should be:
从 {value} 中删除 / 并确保它被列为OperationContract. 它应该是:
[WebGet(UriTemplate = "{value}")]
[OperationContract]
The base URL will come through with the trailing slash, so you are really looking for http://localhost:8000/hello//helpin the current code
基本 URL 将带有尾部斜杠,因此您实际上是http://localhost:8000/hello//help在当前代码中查找
回答by Bevan
A stab in the dark ... by default, arbitrary processes are not permitted to listen on network ports.
暗中刺杀……默认情况下,不允许任意进程侦听网络端口。
When IIS is installed, the account that runs IIS is given permission - if you want other applications run by other accounts (console applications, windows services) to be able to listen to a port, you need to grant the permission.
安装IIS时,运行IIS的账户被授予权限——如果想让其他账户运行的其他应用程序(控制台应用程序、windows服务)能够监听某个端口,则需要授予该权限。
Check out the netsh add urlaclcommand as a starting point.
检查netsh add urlacl命令作为起点。

