Not possible to bypass proxy on UWP mobile device? - c#

I am fairly new to UWP apps development and I created simple UWP app (mainly targeting phones) for purpose of testing and demonstrating behavior of Http libraries on UWP (like System.Net.Http).
One of the scenarios should demonstrate bypassing proxy
var httpClientHandler = new HttpClientHandler();
httpClientHandler.UseProxy = false;
httpClient = new System.Net.Http.HttpClient(httpClientHandler);
var response = await httpClient.SendAsync(request);
but the request send using this setting still goes through proxy (proxy is set in Internet APN settings on the phone).
So I am a bit confused here and feel like I am missing something, and I hope someone will be kind enough to answer me a few questions to help me get the right picture :).
1.) I read documentation and some articles on the topic and there is often mentioned System or Default proxy (usualy it says about IE settings). So what does it mean in context of Windows 10? Is it the proxy set in Settings/Network&Internet/Proxy?
1.1) Is there an equivalent on W10 phone?
2.) Is there some other way how to bypass the Internet APN proxy on mobile device, or it is simply not possible and the UseProxy property is just useless in UWP phone apps?
Thanks in advance for your answers :).
Link to original question on msdn boards
What I read behore asking here:
MSDN documentation on related classes and
Article by program manager on the Windows Networking API

The preferred HTTP API in UWP apps is Windows.Web.Http, you can try:
var handler = new HttpBaseProtocolFilter():
habdler.UseProxy = false;
var client = new HttpClient(handler);

Related

How can I setup proxy settings in c# for Google Cloud Txt-To-Speech API

How to setup a proxy in c# code for Google Text-To-Speech API.
Does somebody knows where to put in the proxy settings for the Google TTS API in c#. Our project runs locally but not on the server behind a firewall, so it has to go via the proxy.
Hope you have a starting point for me ;-)
Thanks!
The intention is that if you've set the system proxy, or the HTTPS_PROXY environment variable, that should just work by default.
However, at the moment there's a bug in Grpc.Net.Client that causes that to fail. (Once it's been fixed and released, we'll obviously update our dependencies for the next release of Google.Cloud.TextToSpeech.V1 and other Cloud libraries.)
The simplest workaround is probably to still use the Grpc.Net.Client implementation of gRPC, but with an additional option:
var client = new TextToSpeechClientBuilder
{
GrpcAdapter = GrpcNetClientAdapter.Default.WithAdditionalOptions(
options => options.HttpHandler = new HttpClientHandler
{
Proxy = new WebProxy("your proxy here"),
UseProxy = true
})
}.Build();

Xamarin Image Source

Apologies if this was asked before.
I am having a rather simple issue, and I am wondering if i am missing something obvious. In my practice Xamarin.Forms app, I am having issue loading the following image source URI: http://lorempixel.com/1920/1080/sports/7/ even though when i go there via my browser; it is fine.
It seems to me like Xamarin needs an image extension for it to work, so for example if i were to have some sort of image online like (https://www.stickpng.com/assets/images/58b061138a4b5bbbc8492951.png , fair warning; this link will download the cat image if you go to it) then it loads up fine.
My question is two fold: Am I missing something simple in my configuration that I need to enable (this is for Android as I don't have an iOS device available atm), and B: Does xamarin even support relative paths?
Code Behind:
var source = new UriImageSource
{
Uri = new Uri("http://lorempixel.com/1920/1080/sports/7/")
};
source.CachingEnabled = false;
ImageOne.Source = source;
Explanation
Both iOS & Android now require https:
Apple will require HTTPS connections for iOS apps by the end of 2016
“Today, I’m proud to say that at the end of 2016, App Transport Security is becoming a requirement for App Store apps,” Apple’s head of security engineering and architecture, Ivan Krstic, said during a WWDC presentation
Android P Will Default to HTTPS Connections for All Apps
[Android P] will default to blocking HTTP traffic in apps by default
Answer
It should be an easy fix - change http to https:
var source = new UriImageSource
{
Uri = new Uri("https://lorempixel.com/1920/1080/sports/7/")
};
source.CachingEnabled = false;
ImageOne.Source = source;

Performance considerations when getting license information for WP app

Introduction
I have a Windows Phone 8.1 Silverlight (WP8.1 SL) based app in the store. Some users complain about performance issues when they have a bad network connection. I searched a bit and came up with the idea that it might be related to new LicenseInformation() that gives me the information of whether the app is running in Trial mode or not. The question is, whether this requires network information or not, and whether CurrentApp.LicenseInformation is a suitable replacement for a WP8.1 SL app.
Background and What I did so far
In general, the app does not need a network connection (no data to load, no advertisements, ...). To confirm that I used Fiddler to watch over the network sent by my phone. The result was that no network traffic is generated. However, the problem still persists.
After a lot of research and playing around I got the feeling that this issue might be related to the code part that checks on whether the app is in trial mode or not. I use the following code to check that.
var li = new LicenseInformation();
if (li.IsTrial()) {
...
}
I do this a couple of times during startup. So in case IsTrial() requires a network connection this could be the actual issue when there is only a bad connection available. But again, I couldn't find anything using Fiddler. The documentation (see here) for LicenseInformation does not mention whether a network connection is required or not.
Searching around I found that there is an updated interface available for both WP 8.1 SL and also W10M UWP.
var li = CurrentApp.LicenseInformation;
if (li.IsTrial) {
...
}
Its documentation clearly states that there is no network connection required for that (see here).
Even though the docs say that CurrentApp.LicenseInformation is also available on WP8 I also found some references that say that you only get a reliable answer for the IsTrial-question when using new LicenseInformation() (e.g. here).
Actual Questions
Is new LicenseInformation() required on WP8.1 SL, or can I use CurrentApp.LicenseInformation as well?
Does new LicenseInformation() require a network connection compared to CurrentApp.LicenseInformation?

Calling SpeechAPI for text to speech on Azure

I have the following very basic TTS code running on my local server
using System.Speech.Synthesis;
...
SpeechSynthesizer reader = new SpeechSynthesizer();
reader.Speak("This is a test");
This code has a dependency on System.Speech for which I have added a Reference in my VS 2015 project.
Works fine but from what I have read and from trying it I know this will not work when the code is hosted on Azure.
I have read several posts on SO querying if it is actually possible to do TTS on azure. Certainly 2 yrs ago it did not appear to be possible. How to get System.Speech on windows azure websites?
All roads seem to lead to the Microsoft Speech API
https://azure.microsoft.com/en-gb/marketplace/partners/speechapis/speechapis/
I have signed up and have gotten my private and sec keys for calling into this API.
However my question is this. How do I actually call the SpeechAPI? What do I have to change in the simple code example above so that this will work when running on azure?
The speech API you referred to at the Azure marketplace is part of an AI Microsoft project called ProjectOxford which offers an array of APIs for computer vision, speech and language.
These are all RESTful APIs, meaning that you will be constructing HTTP requests to send to a hosted online service in the cloud.
The speech-to-text documentation is available here and you can find sample code for various clients on github. Specifically for C# you can see some code in this sample project.
Please note that ProjectOxford is still in preview (Beta). Additional support for using these APIs can be found on the ProjectOxford MSDN forum.
But just to give you an idea of how your program will look like (taken from the above code sample on github):
AccessTokenInfo token;
// Note: Sign up at http://www.projectoxford.ai for the client credentials.
Authentication auth = new Authentication("Your ClientId goes here", "Your Client Secret goes here");
...
token = auth.GetAccessToken();
...
string requestUri = "https://speech.platform.bing.com/synthesize";
var cortana = new Synthesize(new Synthesize.InputOptions()
{
RequestUri = new Uri(requestUri),
// Text to be spoken.
Text = "Hi, how are you doing?",
VoiceType = Gender.Female,
// Refer to the documentation for complete list of supported locales.
Locale = "en-US",
// You can also customize the output voice. Refer to the documentation to view the different
// voices that the TTS service can output.
VoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)",
// Service can return audio in different output format.
OutputFormat = AudioOutputFormat.Riff16Khz16BitMonoPcm,
AuthorizationToken = "Bearer " + token.access_token,
});
cortana.OnAudioAvailable += PlayAudio;
cortana.OnError += ErrorHandler;
cortana.Speak(CancellationToken.None).Wait();

Jabber-net integration

I'd like to ask your help regarding having a Google Talk Bot that will communicate with my code on my server.
I have downloaded Jabber-Net from code.google.com, but the examples there are not enough... I am new to these technologies, and have no clue about:
How will client arrive to my server? where should I change [if any] DNS to my server?
Which server side library should I use?
From the examples I understood that I need to have a Desktop-app running in the background constantly, which doesn't make sense to me.
Does anyone has an example of some better references to understand this better?
[Sorry for my ignorance...]
I'm not sure if I understand what you ask correctly. If you're asking how to connect to chosen server, console sample shows how to do it simply, you basically fill out JID class.
Sample from Jabber-Net
JabberClient jc = new JabberClient();
JID j = new JID(jid);
jc.User = j.User;
jc.Server = j.Server;
jc.NetworkHost = networkHost;
jc.Port = port;
jc.Resource = "Jabber.Net Console Client";
jc.Password = pass;
jc.AutoStartTLS = TLS;
jc.AutoPresence = initialPresence;
If you want to create your own server, there's a library (also running under .NET) called agsxmpp, it allows to create both, server and client, it's open source on MIT/GPL license afair. I don't know if jabber-net enables this feature. On the other hand, there are plenty of free jabber-server if you don't want to just use one of "public" ones, so it may be worth to consider just using something that is ready to be launched.
There's a console sample in the project, you don't need desktop-app (if this is what you were asking?), so you can write service, console app or anything else.
Here's a recent post that shows an example of replying to incoming messages on Gtalk using .NET

Categories

Resources