Azure mobile app offline sync causing a MobileServicePushFailedException -> CancelledByAuthenticationError - c#

As part of a UWP app we're developing at work, we have an Azure mobile app (C#, .NET backend) connected to the client which is supposed to sync up with offline SQLite storage and place CRUD operation requests into a queue so they can be processed by a worker role.
Trouble is, for some reason when we attempt to call PushAsync/PullAsync on the sync context and messages table respectively, it throws a MobileServicePushFailedException. When monitoring this in locals, the PushResult status is "CancelledByAuthenticationError" but this happens even after successfully logging in via one of the providers, and we haven't yet set the table to require authentication anyway so this shouldn't be causing any problems.
Interestingly enough, when this was a mobile SERVICE as opposed to a mobile app running in a Windows 8.1 project instead of a UWP, it worked fine, because the MobileServiceClient constructor in that version of the Nuget package takes the application key as one of its arguments. Unfortunately, we're developing a UWP, so it needed to be migrated and thus we can't use the same constructor any more.
Has anyone come across this before, or does anyone have any idea where we might be able to find further information on this? We haven't been able to find any other concrete references online besides another SO post that was asking about a similar but different issue, and a few other posts that either have no answers or are working with different languages/backends.

Related

Using local webpages as an interface in C#

I have a couple of questions regarding a project I recently started working on. This project requires me to discover devices on the network (broadcasting UDP packets on a specific port), store device information into a database, and then display all the data on a local web page. My questions are:
Can I have a C# program that runs in the background that deals with the device discovery and database management while also running a local webpage for users to interact with?
If so, which kind of Visual Studio project would be the best to
implement this project?
If not, how else could I do this?
We had a problem where we needed a long running process that was initiated by a user but which timed out. We resolved this by running a background Windows service which interacted with the database backing the website. We also have other tasks that we wish to run asynchronously following user action. We run three Windows services on the web server; this solution has been running successfully for a number of years. So, in answer to our specific points:
Yes, as a Windows service separate from your website project
There is a specific project type for this; you will also need to set up an installation project
There may be other ways but I would recommend this approach

Evernote notes overwritten when updated externally

I'm building an app that updates Evernote notes via the Windows C# API. I've noticed an issue where a note that is updated by my app in between sync's in the Windows desktop app (for example) is overwritten.
This also happens when a note is updated in between sync's via another app (e.g. iPhone). To explain this further I've outlined the steps to reproduce the problem using the Windows and iPhone apps.
Please note that in order to repro this there must be a delay in between syncs in the Windows app. Within the app the sync interval can be changed in Tools > Options > Synchronization:
Create note with a reminder in the Windows app
Manually sync Evernote (Windows app)
Sync this note to another device, say the iPhone app
Add a tag to the note & sync (iPhone app)
Complete the reminder in the Windows app
Manually sync Evernote (Windows app)
If the above steps "work", once the Windows app is sync'd the reminder will be active (i.e. not complete) and the tag will be added.
I understand that this sort of scenario is unlikely to happen in a real usage scenario of Evernote, however as I am updating notes regularly via the API the chances of it happening or much more likely.
The ideal solution would be to update specific fields instead of the whole note, however I could see any way to do this.
Anyone have any ideas?
Thanks
When you call NoteStore#updateNote, try to set guid and only attributes you want to update and leave the rest unset.

Azure Mobile App Workflow

After using Azure Mobile Services a year ago, I decided to get back to mobile development but Microsoft changed a lot in their offer and I'm actually struggling to set my project up.
My goal is to create a service whith these features:
.NET backend preferred over the Javascript one (I don't like callbacks :))
SSO (Facebook, Twitter, Google+, Windows Live)
SQL Database (I really need relations, and I already have a T-SQL schema)
Push Notifications (just to Windows and Android for now and with unlimited custom channels so that I can have one channel for each user and avoid dealing with notifications' logic)
Monthly scheduled jobs to update database from an external JSON API and to remove old entries
Mobile Client (with a shared Xamarin library to handle all the data-related stuff and WUP + Android support)
Web Client (I don't have a Mac so I can't build and publish the iOS version, so a web app may be needed as a temporary replacement)
What I did was to:
Open Azure Preview Portal link
Click on New => Web + Mobile => Mobile App
Set the Resource Group with all the needed plans
Added a Data Connection to a newly created SQL Database
Added a Notification Hub with settings for GCM and WNS
Added Mobile Authentication with settings for Microsoft Account, Facebook, Twitter, Google
Created the schema for my SQL Database
Before going on, I'm not sure that this was the correct workflow but documentation is pretty confused and the Get Started sections just discuss about code and not how to properly setup the service and have it running, so I just did the same basic things that I would've done with the old Mobile Service, plus dealing with the SQL Database instead of the NOSQL one.
Now it comes the issue: I have no idea on how to move next, and even the Quickstart projects (both server and client) are not helpful (they're the old TodoItem sample working with the Mobile Service).
The first thing that I wanted to do was to create the Scheduled Job because I actually need to fill the database with the external data before moving forward.
The only thing close to what I need is the WebJob, but I can't schedule it yet and it requires me to upload an exe file while I'd like to be able to write my C# code directly to the server (being able to remotely debug it).
An alternative may be to create a Compute Instace and write an endless loop doing what I need, but this will force me to manually deal with the SQL Database inside the Mobile App Service.
Another issue is related to the SQL Database. As I already wrote, the Quickstart seems to work with the NOSQL included in the old Mobile Service, meaning that I don't have a direct connection to my SQL Database, while I'd like to be able something like
App.MobileService.GetTable<MyTable>()
Plus, having 10 tables, I'd also like to have a way to map them automatically (like NetBeans does for JavaEE projects).
So the question is: what's a good (or the best) workflow to get everything working as I need it or, at least, close to how I need it?
(I know that answers may be opionion-based but they still may be useful since Microsoft's documentation is not complete)
If you have an existing database, you could use Entity Framework Code First to Existing Database. That will generate the C# classes for you.
The database that you create when you add a Data Connection to your Mobile App is an Azure SQL Database by default--I'm not sure why you thought it was NoSQL?
Once you have done this, you can query your tables from the Azure Mobile Apps client SDK. For instance, in Xamarin, the quickstart project does queries as follows (see https://github.com/Azure/azure-mobile-services-quickstarts/blob/MobileApp/client/xamarin.android/ZUMOAPPNAME/ToDoActivity.cs#L126).
var list = await toDoTable.Where (item => item.Complete == false).ToListAsync ();
Finally, regarding your question on WebJobs, you can actually schedule it. See https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/#CreateScheduledCRON for more information. Even though you Web Deploy your webjob target, you can still remote debug it. See this blog post for information: http://www.bursteg.com/remote-debugging-azure-webjobs-attach-a-debugger-from-server-explorer/

Making sure my application is Terminal Services safe

Our company uses a system of which I am the sole developer. It is a C# based desktop application that is run on some 50 workstations or so and all connect to one central SQL Server database.
Our network administrator is now looking at presenting the application through Terminal Services, something that I know nothing about, yet.
As I started Googling around I saw that, apparently, some applications do not work under Terminal Services. MS Paint is mentioned as an example. So this got me wondering, what does a developer need to know to make sure that his/her application works in Terminal Services?
I don't have the time right now to investigate TS in depth but I'm hoping there might be an article somewhere that is written for developers. As in "Things not to do when you develop an application that will be run in Terminal Services".
Terminal Service RemoteApp works pretty well if you application is designed to be multi-user compatible. so you will need to ensure user session related data is not shared, but placed in isolated storage with IsolatedStorageContainment set to DomainIsolationByUser for example.
here are some useful links:
http://www.fmsinc.com/microsoftaccess/terminal-services/remoteapp.htm
https://www.youtube.com/watch?v=Nf20-76dMcg
https://msdn.microsoft.com/en-us/library/3ak841sy%28v=vs.110%29.aspx

Send and Receive Messages between Android App and Winform application

Looked for a long time and didn't find anything that showed this, so I apologize in advance I missed something.
I have an android app running on KitKat (Android 4.4.2) and a Winforms application running Windows 7. I need to send messages between the two of them.
Clearly GCM works to get the message to the Android device. I have code that sends from Winforms to the Android Device using GCM. I cannot find a way to have the Android App send anything BACK though. Is it possible to have a Winforms app RECEIVE a GCM Message? Do I have to use Azure? (All examples there seem to focus on the Windows App store and Windows 8.1 neither one of which can be a solution in this case due to client restraints.)
I'm putting this here in case anyone stumbles across it and has a similar question. This is not really an answer. Still hoping someone comes on here and shows that I am wrong. But after 26 days, no one has even offered a suggestion, so I'm guessing not.
There is no way that I have seen that allows for this the way I had hoped. Windows 7 doesn't have this built in to it (AFAIK). Windows 10 should have it built in, but Windows 7 pre-dates the huge shift to the cloud, and didn't have it in the design. If I were working with something like Xamarin -- which is a cross-platform tool, this might be possible. But there is no concept in Windows 7 for receiving messages from the Cloud.
In order to accomplish this, there would have to be some sort of server added to the mix that could take messages and pass them along via a REST API. This is beyond the scope of what I wanted to code.
The solution I found, and that works for me, is to use Microsofts API that wraps a REST service. This allows for communication to OneDrive, for example. That is what I am using as my intermediary REST server.
Microsoft LIVE SDK
This has a pretty good sample list of Android examples, and can be used for what I need. The good thing is the Upstream is just a simple call, and I don't need to have the Android device poll anything (which kills the battery). The laptop will need to poll OneDrive, but its plugged in so there is no battery life concern.
One thing to be aware of, though, is that Microsoft sort of hints that they don't want a bunch of traffic headed to OneDrive. This is from the overview doc:
Throttling
OneDrive has limits in place to make sure that individuals and apps do
not adversely affect the experience of other users. When an activity
exceeds OneDrive's limits, API requests will be rejected for a period
of time. OneDrive may also return a Retry-After header with the number
of seconds your app should wait before sending more requests.
Although, I have never seen what those limits actually are, so YMMV.

Categories

Resources