HttpNotificationChannel doesn't want to create new channel Uri - c#

I have a weird situation and I'm stuck.
I created push notification in my WindowsPhone application.
After some time my channelUri has expired and now I can't create new one, because the code responsible for that returns the same invalid channel Uri.
What am I doing wrong ?
_pushChannel = HttpNotificationChannel.Find(channelName); //returns null
if (null == _pushChannel)
{
_pushChannel = new HttpNotificationChannel(channelName); //returns channel with expired channelUri
_pushChannel.Open();
}
I also tried using Close() method, but it didn't help anyway.
Any help will be much appreciated.

When a channel expires and a new one is issued you will normally get the same URI back. This is to be expected.
What will be different is that the channel will be been enabled again. If you discover that when you next send to a notification the channel is reported as expired then check what you are sending as invalid payloads will cause the channel to expire when upon sending.

Related

GlobalPay challengeRequestIndicator not showing on Hpp Response

I have a web app that processes payments via globalpay using their HPP solution. It works and is live at the moment but I have tried to implement their save card functionality.
The issue is that with some banks we get and error Invalid Transaction and been advised that it is due to the challenge request indicator not being passed. I have tried adding this in using the HostedPaymentData entity but does not show in the hpp response. there is documentation on builders with the challenege request indicator as well below but not sure how to implement this with my .net request.
They provided me some docs on builders below that has withChallengeRequestIndicator but not sure how to add this to my .net request.
https://github.com/globalpayments/dotnet-sdk/blob/0916facfc690aa4379bbe60d80f08eb40b0e4da2/src/GlobalPayments.Api/Builders/Secure3dBuilder.cs#L163
hostedPaymentData = new HostedPaymentData
{
OfferToSaveCard = true, // display the save card tick box
CustomerExists = true, // new customer
CustomerKey = custKey,
CustomerEmail = userCustomerEmail,
CustomerPhoneMobile = userCustomerPhoneMobile,
AddressesMatch = false,
ChallengeRequestIndicator = ChallengeRequestIndicator.NO_PREFERENCE,
};
Most payments will still process ok but some banks seem to throw and Invalid transaction 101 Error, Global pay advised its to do with this challenge request not being present in the response.
Any help

The client has been disconnected while trying to perform the connection

When trying to connect to a Mosquitto MQTT queue running locally, I get the following error.
Unhandled exception. System.AggregateException: One or more errors occurred. (The client has been disconnected while trying to perform the connection)
---> System.Net.Mqtt.MqttClientException: The client has been disconnected while trying to perform the connection
at System.Net.Mqtt.Sdk.MqttClientImpl.ConnectAsync(MqttClientCredentials credentials, MqttLastWill will, Boolean cleanSession)
I am using the default options when setting up the System.Net.Mqtt.MqttClient.
var config = new MqttConfiguration() {
Port = 1883
};
var client = MqttClient.CreateAsync("localhost", config).Result;
var sessionState = client.ConnectAsync(
new MqttClientCredentials(clientId: "camerasim")).Result;
The following errors show up in the Mosquitto MQTT log.
1644497589: New connection from 172.17.0.1:56792 on port 1883.
1644497589: New client connected from 172.17.0.1:56792 as camerasim (p2, c0, k0).
1644497589: Bad socket read/write on client camerasim: Invalid arguments provided.
The error you are seeing is most likely the result of a change made in Mosquitto 2.0.12:
Fix max_keepalive not applying to MQTT v3.1.1 and v3.1 connections. These clients are now rejected if their keepalive value exceeds max_keepalive. This option allows CVE-2020-13849, which is for the MQTT v3.1.1 protocol itself rather than an implementation, to be addressed.
A change made in 2.0.9 also comes into play:
Fix max_keepalive option not applying to clients connecting with keepalive set to 0. Closes #2117.
These changes were made to address an issue with the MQTT protocol itself which permits a denial of service attack (CVE-2020-13849).
The default value for max_keepalive is 65535 so this change means that attempting to connect with keep alive set to 0 (meaning no keepalive) will fail unless mosquitto.conf specifies max_keepalive 0. Unfortunately the error logged (Bad socket read/write on client XXXXXYYYYY: Invalid arguments provided.) does not really highlight the cause.
There are two available solutions:
Specify max_keepalive 0 in mosquitto.conf (Mosquitto 2.0.13 or later).
When connecting specify a keep alive between 1 and 65535. In xamarin/mqtt this means adding KeepAliveSecs to your config; this defaults to 0.
Note that setting KeepAliveSecs = 1 (as per your answer) will allow you to connect but is probably a little short for most users (KeepAliveSecs = 60 may be more appropriate). e.g.
var configuration = new MqttConfiguration {
Port = 1883,
KeepAliveSecs = 60,
WaitTimeoutSecs = 2,
};
I realise that you have already found a solution to this but as it's likely to affect others I thought it was worth explaining the root cause of the issue. Many MQTT libraries default keep alive to 0 so will be impacted (e.g. Go Paho had an issue logged).
I was able to successfully make a connection by changing the default KeepAliveSecs property when setting up the MqttConfiguration.
var config = new MqttConfiguration() {
KeepAliveSecs = 1,
Port = 1883
};

How to bind and update a list view Item to a RequestBin http page

I'm developing a graphic user interface where the user can send a message to mutuple user using Twilio API in c#
I'm trying to bind a list view to the status of each number being sent and I also want to know the status of the message every time the user click on refresh list view
public void sendSMS(string ssid, string token , string fromNumber, List<string>TOnumbersList ,string msgBody )
{
TwilioClient.Init(ssid, token);
foreach (var toNumber in TOnumbersList)
{
var message = MessageResource.Create(
to: new PhoneNumber(toNumber),
from: new PhoneNumber(fromNumber),
body: msgBody,
provideFeedback: true,
statusCallback: new Uri("http://requestb.in/1jnk4451"));
ListViewItem items = new ListViewItem(message.To);//This show the number being sent to ( delivered number)
items.SubItems.Add(message.Status.ToString()); //Refresh the status WHERE number = message.To
items.SubItems.Add(message.ErrorCode.ToString());//Show error code in case
items.SubItems.Add(message.ErrorMessage); // In case error message show them
listView1.Items.AddRange(new ListViewItem[] { items });
}
}
Twilio API is doing the perfect job updating the status so everytime I go click the link I can see the status. as explained in this documentation Track Delivery Status of Messages in C#
But is It possible to bind a list view so it can be updated everytime the user click on refresh list view ?
Or what is the best way to dynamically show the message status from the URI http://requestb.in/1jnk4451? Maybe embedding a webpage would be better ?
Thank you
Twilio developer evangelist here.
Rather than using the RequestBin URL, if you provide a URL to your own application then you can write an endpoint that receives the status updates of the messages. That way you can store the status yourself and update the list view without having to loop through all the messages.
[Edit] In more detail:
When you send an SMS message with Twilio using the REST API you can set a statusCallback URL to receive updates about the message as it processes through from Twilio to the network and the device.
Twilio will make HTTP requests to this URL as the message goes through each state, the possible states being queued, failed, sent, delivered, or undelivered. Twilio sends a number of parameters as part of this request, some are general ones about the message and some are about the actual status.
To receive these requests you need to set up a web server. I'm not a C# developer I'm afraid, however we have a guide on how to set up a C# and ASP.NET MVC environment that can receive webhooks that should be able to help you there.
Let me know if this helps a bit more!

ListTweetOnUserTimeline returns null

I'm using TweetSharp for C#, and I'm successfully able to publish tweets to twitter via this.
However, I'm trying to read the most recent tweets from the account's timeline, but I keep getting null back every time I try to get the data. The following code returns null
string consumerKey = <consumerKey>;
string consumerSecret = <consumerSecret>;
TwitterService service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(consumerKey, consumerSecret);
var options = new ListTweetsOnUserTimelineOptions()
{
ScreenName = screenName,
SinceId = 0,
Count = 5
};
var currentTweets = service.ListTweetsOnUserTimeline(options);
I've tried using UserId instead of ScreenName, but I still get null as a result fir currentTweets. All the examples I can find are pointing to this method, but it doesn't work.
Any Ideas?
If you're using an older version of .NET, then you may be using TLS 1.1 under the hood to communicate with Twitter. If you are doing this, then the AuthenticateWith will fail silently, and nothing will work.
You need to add the code
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
In order to make this work.
Also you should be passing the accessToken and accessTokenSecret to AuthenticateWith, not the consumer keys, as mentioned above.
I think your problem is the AuthenticateWith call. You appear to be passing the consumer token and secret again, but the AuthenticateWith overload that takes only two arguments expects a user token and secret. I suspect you are therefore getting an unauthorised response (not sure why you don't get an error).
I would suggest either removing the AuthenticateWith call (you've already provided the consumer token in the constructor), or changing it so you pass details for a valid user token instead of the consumer one.
You could also check the Response property on the twitter service after your call completes, and inspect the http status code/reason phrase/content etc. to see if that gives you more detail about what is going wrong.

How to Know the duration of time a token or connection was streaming it's video to a session in opentok

I published to a session in opentok with a token and streamed my video.
Now how can I get information like how much time did my video streamed, and many other information which can be useful for data analysis?
var apiKey = "*****";
var sessionId = "**************************";
var token = "************";
var publisher = TB.initPublisher(apiKey);
var session = TB.initSession(sessionId);
session.connect(apiKey, token);
session.addEventListener("sessionConnected", sessionConnectedHandler);
session.addEventListener("streamCreated", streamCreatedHandler);
in reference to this question:
You have to keep track of these data yourself. For example, after creating a publisher you can send a post request to your server with the current timestamp Date.now()
When the user disconnects, you will get a sessionDisconnected event from someone else in the session, you can send an event to your server with the current timestamp Date.now() to mark the end time.
To identify the streams that have been disconnected, simply make sure you are sending the user's connectionId in your requests: session.connection.connectionId and stream.connection.connectionId
Alternatively, you can try out OpenTok raptor SDK, which is simply a Java SDK that you can use in your Java backend to get a request every time a user connects/disconnects to a session and other events. Unfortunately this only works with Java for now, OpenTok will work to support more SDKs soon.

Categories

Resources