提问人:Eduardo García 提问时间:10/16/2023 最后编辑:Eduardo García 更新时间:10/16/2023 访问量:42
System.ServiceModel.CommunicationException:TCP 错误(10049:请求的地址在其上下文中无效) 如何将 Azure 的 VM 用作服务器
System.ServiceModel.CommunicationException:A TCP error(10049: The requested address is not valid in its context) How to use a VM of Azure as Server
问:
我正在尝试这样做,azure 的 VM 是我的服务器。 我在带有 WCF 的 Visual Studio 上使用 C#。 我的主机的app.config是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<services>
<service behaviorConfiguration="mexBehavior" name="TimbiricheService.UserManagerService">
<endpoint address="UserManagerService" binding="netTcpBinding"
bindingConfiguration="" contract="TimbiricheService.IUserManager" />
<endpoint address="UserManagerService" binding="netTcpBinding"
bindingConfiguration="" contract="TimbiricheService.IManagerOnlineUsers" />
<host>
<baseAddresses>
<add baseAddress="http://20.81.133.87:8082" />
<add baseAddress="net.tcp://20.81.133.87:8081" />
</baseAddresses>
</host>
</service>
</services>
</configuration>
我的 VM 具有以下规格:
和下一个规则
而且我已经停用了VM的防火墙
当我运行主机时,它会在 host.open() 行上抛出下一个摘录;
namespace TimbiricheHost
{
internal class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(TimbiricheService.UserManagerService)))
{
host.Open();
Console.WriteLine("Server is running");
Console.ReadLine();
}
}
}
}
例外:
System.ServiceModel.CommunicationException
HResult=0x80131501
Message=A TCP error (10049: The requested address is not valid in its context) occurred while listening on IP Endpoint=20.81.133.87:8081.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Channels.SocketConnectionListener.Listen()
at System.ServiceModel.Channels.BufferedConnectionListener.Listen()
at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at TimbiricheHost.Program.Main(String[] args) in C:\Users\timbiriche\Documents\GitHub\Timbiriche-The-Game\Timbiriche-Service\TimbiricheHost\Program.cs:line 16
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
SocketException: The requested address is not valid in its context
我该如何解决?
因为如果我把私有 IP 放在基址上,它就可以工作,但使用公共 IP 它就不起作用了
我已经禁用了防火墙,在 Azure 上添加了入站和出站端口的规则,以及我之前评论过的内容。
答: 暂无答案
评论