Connection error SASL error with QPID and AmqNetLite - c#

I am not familiar with AMQP.
I try to connect a AmqpNetLite program to a Qpid server and I get the following exception :
Amqp.AmqpException: sasl-mechanisms(sasl-server-mechanisms:[CRAM-MD5,SCRAM-SHA-1,SCRAM-SHA-256])
Note : I am able to connect to a basic AMQP server, but not QPID.
Here is the code to create the connection:
Please tell where to start to fix my problem.
void Main(string[] args)
{
try
{
Address address = new Address("amqp://guest:guest#localhost:5672");
Connection connection = new Connection(address);
Session session = new Session(connection);
ReceiverLink receiver = new ReceiverLink(session, "receiver-link", "queue");
Message message = receiver.Receive();
receiver.Accept(message);
receiver.Close();
session.Close();
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}

The error would seem to indicate that the broker is not able to provide the client with a SASL mechanism that it supports. I think that AmqpNetLite only does ANONYMOUS, PLAIN and EXTERNAL but perhaps that's changed. You could look into your broker configuration and make one of those mechanisms available to the client and that will probably allow for a match and successful authentication. Or you could use an SSL connection which would then allow those SASL mechanisms to work and provide a bit of extra security for you connection.
The security section of the Broker-J documentation site should shed some light on this for you.

Related

IBMMQDotnet client retry mechanism

Hi everyone i am completely new to queues and especialy to IBMMQDotnet cleint library. Currently my application trying to send DTO object to the queue and sometimes it could faailed for various reasons like exception occuring or network issue. Is there any retrie mechanism ?i would like to implement retry mechansim, i tried to google it but could not found any example. Bellow is the current code
if (!TryConnectToQueueManager())
{
return;
}
using var destination = GetMqObjectForWrite(message.Destination, message.DestinationType);
var mqMessage = new MQMessage
{
Format = MQC.MQFMT_STRING,
CharacterSet = 1208
};
if (message.Headers?.Count > 0)
{
foreach (var (key, value) in message.Headers)
{
mqMessage.SetStringProperty(key, value);
}
}
mqMessage.WriteString(JsonSerializer.Serialize(message.Data));
destination.Put(mqMessage);
destination.Close();
IBM MQ provides a feature called as Client Auto Reconnect.You could refer the following KC page Client Auto Reconnect
If there is a connection failure because of the network issue, the IBM MQ client will try to re-establish a connection to the Queue Manager for a specific time period(which is configurable) before throwing an exception to the application
You could refer to the sample "SimpleClientAutoReconnectPut" & "SimpleClientAutoReconnectGet" which are available as part of the client installation.

Azure and SignalR: System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions

I'm currently experiencing this issue at a high frequency:
System.Net.Sockets.SocketException: An attempt was made to access a
socket in a way forbidden by its access permissions
Sometimes it happens when connecting to Azure Storage from my web app (code below), but most of the time it happens with SignalR.
Based on debug diag, I see the following:
394 client connections in w3p.dmp have been executing a request for more than 90 seconds.
Based on the memory dump, there are a significant number of connections being made to /signalr/connect and /signalr/reconnect.
It looks like I'm using AspNet.SignalR.WebSockets.WebSocketHandler to make SignalR connections from within code. At this point I'm not sure what to look for though - what could be the culprit? We have a web service living in Azure, with web apps and mobile apps connecting to a SignalR backplane (redis).
Screen from debug diag
Code for Azure Storage
public void EnqueueRequest(int requestId)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings.Get("AzureStorageConnectionString"));
// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a queue.
CloudQueue queue = queueClient.GetQueueReference(ConfigurationManager.AppSettings.Get("requestQueueName"));
// Create a message and add it to the queue.
CloudQueueMessage message = new CloudQueueMessage(castingCallId.ToString(CultureInfo.InvariantCulture));
queue.AddMessage(message);
}
Hub Proxy Code
var baseUrl = _dbContext.CurrentTenant.BaseUrl;
_hubConnection = new HubConnection(baseUrl);
_hubProxy = _hubConnection.CreateHubProxy("appHub");
await _hubConnection.Start();
string serialized = null;
try
{
serialized = JsonSerializerExtensions.SerializeObject(data).SanitizeData();
await _hubProxy.Invoke((isTypingNotification ? "SendTypingNotification" : "SendClientNotification"), serialized, username);
}
catch (Exception exception)
{
LogError("1: " + exception);
}
SB2055 and I worked on this and made the following changes to eliminate this issue:
Do not create a HubConnection for each message to send. A HubConnection is a heavyweight object and should be created once and reused. You can recreate the IHubProxy multiple times if needed. You can accomplish this by setting the HubConnection as a class static member variable.
We changed the connection type from web sockets to long polling.

Npgsql : is the server down or a bad password?

I am trying to connect to PostgreSQL database from my c# application like so:
NpgsqlConnection MyConnection = new
NpgsqlConnection("Server=localhost;Port=5432;User Id=postgres;Password=mypassword;Database=mydatabase;");
try
{
MyConnection.Open();
}
catch (NpgsqlException pe)
{
//Code "28P01" = user name or password is wrong
// server ip or port is wrong
}
the question is : NpgsqlException.code does not differentiate between the following conditions:
server ip /port number is wrong
user name and password combination is wrong
Code "28P01" is returned in both cases. obviously Npgsql can see that the server is there and responding with some data indicating bad user name or password (condition #2 above) or nobody seem to be there (condition #1 above)
how can i differentiate between those 2 cases in my code?
with Npgsql v 3.0.2.0 (not sure about older versions) if the IP/hostname is wrong an Exception with code =-2146233083 with be thrown. if however the IP/hostname is correct but the port number is wrong Exception with code= -2147467259 with be thrown. if the IP/port is correct but username /password is wrong a NpgsqlException with code = "28P01" will be thrown.
You're probably using Npgsql 2.x; the new Npgsql 3.x throws NpgsqlException only when errors are received from a PostgreSQL server. Network connection errors are raised as SocketException etc. You're encouraged to upgrade.
By the way: I couldn't reproduce your exact findings even with Npgql 2.x, connecting to a wrong port or a wrong IP resulted in an NpgsqlException with Code being an empty string, not 28P01.

Are they any additional requirements for UPNP/WCF porting?

Im using http://managedupnp.codeplex.com/ API to open up a port using UPNP on my NetGear DG834g ROUTER with the following code..
public void UPNPOpenPort(int port)
{
Services lsServices;
lsServices = Discovery.FindServices("urn:schemas-upnp-org:service:WANPPPConnection:1");
if (lsServices.Count > 0)
using (Service lsService = lsServices[0])
{
try
{
object[] loObj = new object[] { "", port, "TCP", port, "10.0.0.100", true, "Custom Mapping", 0 };
lsService.InvokeAction("AddPortMapping", loObj);
}
catch (Exception loE)
{
MessageBox.Show(
String.Format(
"{0}: HTTPSTATUS: {1}",
loE.Message,
lsService.LastTransportStatus));
}
}
else
{
MessageBox.Show("Doh No Router Found");
return;
}
}
I have a service host with a NetTCP binding with the same port im feeding into the sub routine to set the UPNP forwarding and I can see an active UPNP record on the router configuration. I can see the port is listening on my local machine and other PC's on my LAN can connect to the port however using an online Port checker it shows as closed, even though the Router says that it should be forwarding to the correct internal IP.
Does anyone have any ideas or am i missing something?
Best Regards,
Christopher Leach
Yes. I performed a factory restore on the router, enabled UPnP, opened the service host and created a forward. It worked.
Even Teredo decided to come online.
Its great to know from a beginners perspective that its not always your codes(your understanding) fault. Sometimes its your hardware.
Thanks,
Christopher Leach

How can i disable the relaying and use my code as an authenticated client?

So there are many posts on this error i'm getting. But most deal with IIS.
Mailbox unavailable. The server response was: 5.7.1 Unable to relay
I have ported my code to console to see if i still get this error, and i do. It would seem as though it's still using ISS as a relay or something even though this is a console application?
I have spoken to the Exchange Admin and he is not going to open up the mail server for any relaying or allow my server to do so. So i would like to make my C# code send out the email as a regular authenticated client as if it were outlook.
My code below works if i'm sending it to someone within my own domain but not if the recipient is outside the domain.
How can i disable the relaying and use my code as an authenticated client so i can send emails to people outside my domain?
CODE:
static void Main(string[] args)
{
Console.WriteLine("Sending Mail...");
try
{
SmtpClient _SMTPServer = new SmtpClient("companymailserver", 587);
_SMTPServer.Credentials = new System.Net.NetworkCredential("myusername", "mypassword");
MailMessage _mailMessage = new MailMessage();
_mailMessage.To.Add(new MailAddress("someone#gmail.com"));
_mailMessage.From = new MailAddress("myself#mycompanydomain.com");
_mailMessage.IsBodyHtml = false;
_mailMessage.Subject = "This is a test";
_mailMessage.Body = "This is the body";
_SMTPServer.Send(_mailMessage);
}
catch (Exception err)
{
Console.WriteLine("error: " + err.Message);
}
Console.WriteLine("Press any key to continue...");
Console.Read();
}
UPDATE #1
The strange thing is no matter what credentials i put i get the same 'Unable to relay' error. As if it's defaulting to relay and ignoring my SmtpClient settings.
I'm guessing that the authentication failed. Try including the domain name.
_SMTPServer.Credentials =
new System.Net.NetworkCredential("myusername", "mypassword", "mydomain");
Also, be sure to set UseDefaultCredentials to false
_SMTPServer.UseDefaultCredentials = false;

Categories