WCF 服务主机配置 - 请尝试将 HTTP 端口更改为 8732 [英] WCF Service Host Configuration - Please try changing the HTTP port to 8732

查看:42
本文介绍了WCF 服务主机配置 - 请尝试将 HTTP 端口更改为 8732的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 PC 上有一个基于 WCF 服务的复杂解决方案,但由于安装 Windows 8.1 出现问题,我不得不刷新"我的 PC.现在我已经重新安装了 Visual Studio 2012,我的项目不再正常运行.

I had a complex WCF service based solution working on my PC but due to a problem installing Windows 8.1 I had to 'Refresh' my PC. Now that I've reinstalled Visual Studio 2012 my project no longer functions correctly.

当我调试单元测试时,wcfservicehost 显示错误:

When I debug a unit test the wcfservicehost displays an error:

Please try changing the HTTP port to 8733 or running as Administrator.
System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8732/Design_Time_Addresses/MyWCFService/Name/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ---> System.Net.HttpListenerException: Access is denied

显然,通常的解决方案是以管理员身份运行 Visual Studio(可能是因为它随后覆盖了某处的某些内容)但是我无法这样做,因为我需要在网络驱动器上引用 DLL,而网络驱动器不能以管理员身份运行时访问.

Apparently the usual solution to this is to run Visual Studio as administrator (possibly because it then overwrites something somewhere) however I'm unable to do this as I'm required to reference DLLs on a network drive and network drives cannot be accessed when you run as administrator.

我假设某处有一个配置文件或注册表项,用于确定 Visual Studio 或 WCF 服务主机在运行时使用的端口,并且那里有我以前安装的 Windows 的剩余项.

I'm assuming that somewhere there is a configuration file or registry entry that determines which port Visual Studio or the WCF Service Host uses when running and that there is a leftover entry in there from my previous Windows installation.

要将端口更改为 8733 需要编辑每个服务,重新引用它们,然后重建解决方案并希望它有效.

To change the port to 8733 would require editing every service, re-referencing them and then rebuilding the solution and hoping that it works.

有没有办法设置或强制 WCF 服务主机使用的端口?

Is there a way to set or force the port that WCF Service Host uses?

推荐答案

经过一番挖掘和研究,我发现最新版本的 Windows 强制执行安全设置,阻止您侦听任何端口.我假设安装 Visual Studio 后,它会保留一个端口供自己使用,以便您可以托管并调试 Web 服务.这是我的开发机器上的 localhost:8732 端口,但重新安装 Visual Studio 后,它现在是 localhost:8733,不幸的是,解决方案中的所有 app.config 文件都指向端口 8732.

After a bit of digging around and research I found out that recent versions of Windows enforce security settings that prevent you from listening to any ports. I’m assuming that when Visual Studio is installed it reserves a port for it’s own use so that you can host and thus debug web services. This was the localhost:8732 port on my development machine but with reinstalling Visual studio it is now localhost:8733, unfortunately all my app.config files in the solution point to port 8732.

运行提升的命令提示符并执行 netsh http show urlacl.这显示了我发现的保留端口列表:

Run an elevated command prompt and execute netsh http show urlacl. This displays the list of reserved ports amongst which I found this:

Reserved URL            : http://+:8733/Design_Time_Addresses/
User: NT AUTHORITY\INTERACTIVE

我假设这是在安装 Visual Studio 时添加的条目.

Which, I’m assuming, is the entry added when Visual Studio was installed.

执行以下命令保留8732 url/port:

Executing the following command reserves the 8732 url/port:

netsh http add urlacl url=http://+:8732/ user=WORK\Clara

重新启动 Visual Studio,我的解决方案突然再次起作用.

Restart Visual Studio and all of a sudden my solution works again.

这篇关于WCF 服务主机配置 - 请尝试将 HTTP 端口更改为 8732的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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