为什么我会收到 WCF 异常“HTTP 无法注册 URL http://+:80/MyService/"? [英] Why do I get WCF Exception "HTTP could not register URL http://+:80/MyService/"

查看:34
本文介绍了为什么我会收到 WCF 异常“HTTP 无法注册 URL http://+:80/MyService/"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用它需要使用的端点地址创建我的主机,如下所示:

I create my host with the endpointaddress it needs to use, like this:

Uri endpointAddress = new Uri("http://127.0.0.1:5555/MyService");
ServiceHost host = new ServiceHost(myServiceType, endpointAddress);
host.AddServiceEndpoint(implementedContract, basicHttpBinding, string.Empty);

但是当我稍后执行 host.Open(); 我收到异常HTTP 无法注册 URL http://+:80/MyService/ 因为另一个应用程序正在使用 TCP 端口 80".结果是一样的,当我做

but when I later do host.Open(); I get the exception "HTTP could not register URL http://+:80/MyService/ because TCP port 80 is being used by another application". The result is the same when I do

host.AddServiceEndpoint(implementedContract, basicHttpBinding, endpointAddress);

为什么它会尝试使用端口 80 做任何事情?我该如何解决这个问题?

Why would it try to do anything with port 80? How can I solve this?

更新在尝试提供更完整的代码示例时,我找到了罪魁祸首.我添加了一个 ServiceMetadataBehavior 如下:

Update While trying to provide a more complete code sample, I found the culprit. I added a ServiceMetadataBehavior as follows:

ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.ExternalMetadataLocation = new Uri(this.ExternalMetadataLocation);
smb.HttpGetEnabled = true;
smb.HttpGetUrl = this.RemovePort(this.EndpointAddress);
host.Description.Behaviors.Add(smb());

过去我似乎需要从 URL 中删除端口才能使其正常工作,但现在这正是导致问题的原因.

It seems that in the past I needed to remove the port from the URL to get this to work, but now that's exactly what causes the problem.

所以 Pratik 是对的:元数据是问题所在,当然端口 80 的问题是有一些新安装的应用程序使用该端口.

So Pratik is right: metadata were the problem, and of course the problem with port 80 is that there's some newly installed application using that port.

谢谢,问候,

米尔.

推荐答案

这是因为端口 80 已被另一个应用程序使用,如错误消息所述,很可能是本地 IIS 服务器.尝试停止 IIS 并查看,或使用其他端口.在 vista 及以上,您可以使用 netsh 命令检查哪些端口已经被保留

This is because port 80 is already used by another applicatiion as the error message says, most likely by local IIS server. Try stopping IIS and see, or use another port. On vista and above you can use netsh command to check which ports are already reserved

顺便说一句,您在 app.config 或 web.config 文件中有 http 元数据或 mex 端点吗?

BTW do you have http metadata or mex endpoints in the app.config or web.config file ?

这篇关于为什么我会收到 WCF 异常“HTTP 无法注册 URL http://+:80/MyService/"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆