APNS implementation in C# - c#

I am trying to implement push notification services in windows by following this link.
Starting from MAC I am able to create SSL certificate(cer) and key (p12) files. I also installed these two files on Windows server by following this link.
Now the issue is, when I execute .Net code, I am able to send a message but in the response I'm getting an exception. When it goes into the ReadResponse it gives the error Input string was not in a correct format on this line :
payLoadIndex = ((Convert.ToInt16(payLoadId)) - 1000);
It happens because payLoadId is blank. It says that "Notification successfully sent to APNS server for Device Token" but I get no notifications. I assume if this ReadResponse worked I would be able to know what the error was.
One thing I noted in some post is that after following the above procedure they create the PKCS12 format file for the notifications to work, using OpenSSL.
If this is required, which key should I use, "p12" or "PKCS12"?

Related

Getting Error on Kendo UI Folder Upload - ERR_HTTP2_PROTOCOL_ERROR

I am using Telerik Kendo File Upload for uploading folder.
In Production environment, few users are complaining issue with Folder Upload, during upload few files get errored out, using Developer tool in the console tab it logs "ERR_HTTP2_PROTOCOL_ERROR" error as attached for the failed files.
When i am trying i am not getting this error and all folders are getting uploaded properly. I asked user to share the files for which they are facing error and when i tried it uploaded successfully. When user tried again uploading same files which errored out it got succeeded today which were failing yesterday but sill there are files which is giving the same error.
I went through a post where it say the problem could be due to use of HTTP/2 and when they switched to HTTP /1.1 it worked fine. We are also using HTTP/2 but we don't have option of going back to HTTP/1.1. Link below :
https://www.telerik.com/forums/problems-with-multi-file-upload-and-http-2
Any suggestions ?
This is because on your clients machine http/2 is not enabled thus the error prompts.
If you look in your local machine you will see that under your server, you have Https protocol enabled and a valid certificate.
Your clients either lack a valid certificate on the server or are using the site through Http protocol.
you can learn more here:
Http/2 explanation
SETTINGS_MAX_CONCURRENT_STREAMS (0x3):
Indicates the maximum number of concurrent streams that the sender will allow. This limit is directional: it applies to the number of streams that the sender permits the receiver to create. Initially, there is no limit to this value. It is recommended that this value be no smaller than 100, so as to not unnecessarily limit parallelism.
A value of 0 for SETTINGS_MAX_CONCURRENT_STREAMS SHOULD NOT be treated as special by endpoints. A zero value does prevent the creation of new streams; however, this can also happen for any limit that is exhausted with active streams. Servers SHOULD only set a zero value for short durations; if a server does not wish to accept requests, closing the connection is more appropriate.
Resolution : : Add “Http2MaxConcurrentClientStreams” under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP\Parameters
In Registry and restart server.
Set this value to 100 or >100

MongoClient ignores the connection string

I just started to use MongoDB(4.4) and its C# driver. I set up my MongoDB with the default option, localhost:27017. Then I turned on the authorization, created a superuser with root permission, like this:
db.createUser(
{
user: "superuser",
pwd: "123",
roles: [ "root" ]
}
)
I tested it on both Mongo shell and Compass, it all worked as expected, connected with correct password, and denied with the wrong one.
Then I created a C# windows form app, use NuGet to install all required packages such as MongoDB.Driver for C#(v2.11.0) and its related packages such as MongoDB.Bson, etc
After that, I used the following code to create a MongoClient:
MongoClient client = new MongoClient( "mongodb://superuser:12#localhost:27017" );
So I expected it should throw an exception because I used the wrong password, "12" in this case. But it didn't. Then I tried to list database names with:
client.ListDatabaseNames();
It threw a timeout exception: "A timeout occured after 30000ms selecting a server using CompositeServerSelector"
Even I used the correct password or turned off the authorization, and just go with "mongodb://localhost:27017" or ""mongodb://127.0.0.1:27017", it still threw the same timeout exception.
It feels like something wrong with that client it created which caused the timeout issue later on. But I couldn't figure out what I am missing.
Thank you for your help!
Edit:
The same code works perfectly in a console app, just not a windows form app, which really confuses me.
After trial and error for 2 days, I finally found a work around for this issue, still don't know why this works though.
So basically I have to split the MongoClient creation and its following function calls separately. I can't do anything related to the MongoClient right after its creation. For example, the following throws the time out exception:
MongoClient client = new MongoClient( "mongodb://localhost:27017" ); //I turned off authorization
client.ListDatabaseNames(); //Throw time out exception here!!!
I have to split them separately in 2 functions call, like one in a "Connect" button event, another one in a "ListDatabaseNames" button event.
Once I did that, everything works fine.
mongodb://superuser:12#localhost:27017?authMechanism=SCRAM-SHA-1
because dotNet not support SCRAM-SHA-256 yet
Creating a client does not perform any network operations like connecting to your MongoDB deployment - that is done in background. Hence incorrect credentials won't make client creation fail.
mongo shell works differently and compass probably performs some queries that would fail if credentials aren't correct.
Why you are getting a timeout error - my guess is it's an ipv4/ipv6 difference. Try 127.0.0.1 instead of localhost. If this doesn't help enable debug information in your driver.

ErrorMessage while open connection to Denodo via npgsql in c#

sorry, if this is question is (to) easy for stackoverflow community.
I am trying to connect to Denodo (Version 7), via c# code.
I installed npqsql and created a connection string with: {host} {port} {username} {passwd} {database} and the SSL-Mode as required.
(user and pwd combination was checked via Launch Pad)
For trying I use a simple select statement.
If I call Open() on my NpqsqlConnection object I get the error message {"Received unexpected backend message ParseComplete. Please file a bug."}
For beeing sure I tried to ping the host, which works fine. And if I try without SSl, the error message indicates that the SSl is required, therefor I think the correct backend is found.
Could someone give me a hint?
Thanks
Jessi
I checked the Denodo Community, and the given examples: https://community.denodo.com/docs/html/browse/6.0/vdp/developer/access_through_an_ado.net_data_provider/access_through_an_ado.net_data_provider
https://community.denodo.com/answers/question/details?questionId=90670000000XcbkAAC&title=How+to+execute+C%23+program+using+vdp-clients-ADO.NET

ProcessReceivedMessage Error in MqttDotNet

I am building a .NET IoT project that requires MQTT for communication. For the broker I use GnatMQ and for clients I use MqttDotNet (for mobile compatibility). The client library builds, connects, and sends messages fine but I get an error whenever the client’s PublishArrivedDelegate is triggered (i.e. message received event).
The error occurs on retained messages as well as standard received messages. The MqttDotNet error log is here.
Console output:
It seems the error is captured in the QoSManager.cs on line 91:
else if (mess.QualityOfService == QoS.OnceAndOnceOnly)
{
_responses.Add(mess.MessageID, new MqttPubrelMessage(mess.MessageID));
}
NOTE: I am using the raw libraries (as they are) without added code.
Has anyone tried these libraries and can maybe confirm that it worked for them without issues? Until then, I guess it's debugging till the extreme.
Update 1: The error only persists on subscribe with QoS level 2.
Update 2: The error can be prevented by adding a handle to prevent duplicates from being added to the hashtable, as pointed out by #hardillb . But this does not SOLVE the actual issue here.
The issue still persists on publish and subscribe with QOS 2. The problem is that the onClientPublishedArrived is being triggered exactly 3 times whenever a message gets received and exactly 2 times when a message get received as retained. NOTE that when I test this with HiveMQ the issue is gone. The problem only persists when using the GnatMQ broker.
Looks like you are trying to add duplicate keys to a Hashtable, this will be being caused by mess.MessageID returning the same value for multiple messages.
The C# implementation looks like it throws an exception rather replacing the original value with the new value.
If you just need a unique key for the Hashtable you could use something like the timestamp

Accessing Google Spreadsheets with C# using Google Data API fails with Mono

I'm trying to access my Google spreadsheets using the GData API. I have followed the example which looks like:
var service = new SpreadsheetsService("myTest");
service.setUserCredentials(username, password);
var query = new SpreadsheetQuery();
var feed = service.Query(query);
This should return a feed with a list of spreadsheets. However this fails with:
Google.GData.Client.GDataRequestException: Execution of request failed: http://spreadsheets.google.com/feeds/spreadsheets/private/full ---> System.Net.WebException: The remote server returned an error: (404) Not Found.
When I try the above link directly in my browser I'm able to download the feed, as long as I'm logged in into my Google account.
Some further information:
I'm not behind a firewall
I have checked my username (maurits.rijk at gmail.com) and password several times
I am using Mandriva in VirtualBox on a MacBook
All my code is compiled with Mono
I tried the same functionality in Java on OS-X. That code runs as expected.
Looks like a Mono problem to me.
Could you test with fiddler to test if your call reach the server?
I found the problem and solution on Google code, Issue 88 as comment 8.
In short, using
mozroots --import --sync --quiet
solves this problem. For me it now works.

Categories