【发布时间】:2012-03-30 07:07:47
【问题描述】:
我正在将我的 C# 控制台应用程序迁移到 Azure。我的应用程序使用 HttpListener 在特定端口上侦听 http 请求。当我以 Worker 角色在本地尝试以下测试代码时,我得到一个异常(ComputeEmulator 屏幕中的类似打印输出)说:
HttpListenerException - “该进程无法访问该文件,因为它正被另一个进程使用”。
注意:我已在服务配置文件中将端口配置为 2020。我还注意到从 RoleEnvironment show 2020 检索到的端口,但这是否假设显示不同的端口,因为它应该被重新映射到与配置的外部端口号不同的端口?
// ========== Test code starts ==============
string ipAddress = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Ecard"].IPEndpoint.Address.ToString();
int port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Ecard"].IPEndpoint.Port;
string uri = @"http://" + ipAddress + ":" + port + "/";
try
{
httpListener = new HttpListener();
httpListener.Prefixes.Add(uri);
httpListener.Start();
}
catch (Exception e)
{
Trace.WriteLine(e.Message);
}
// Test code ends.
非常感谢您的帮助。
【问题讨论】:
标签: azure httplistener