所以这是连接代码.
var factory = new ConnectionFactory
{
HostName = "myserver",
UserName = "testuser",
Password = "testuserpassword"
};
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "LOG",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "",
routingKey: "LOG",
basicProperties: null,
body: body);
Console.WriteLine(" [x] Sent {0}", message);
}
我在一个控制台应用程序中测试它,一切正常,我可以发送和接收消息.
如果我然后将上面相同的代码复制并粘贴到我的WPF应用程序中,我会在这里得到一个例外
connection = factory.CreateConnection()
例外
Exception thrown: ‘System.ArgumentException’ in RabbitMQ.Client.dll
Additional information: No ip address could be resolved for myserver
如果我将“myserver”更改为服务器ip,我会得到同样的错误.
不明白为什么代码在一个应用程序中工作而不在另一个应用程序中.