Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing web API within WASM #3250

Closed
5 tasks
ZeProgFactory opened this issue May 26, 2020 · 7 comments
Closed
5 tasks

Accessing web API within WASM #3250

ZeProgFactory opened this issue May 26, 2020 · 7 comments
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/bug Something isn't working

Comments

@ZeProgFactory
Copy link

We made several tests in order to access web API. We found no problems when in UWP context but when we are in WASM context we only could retrieve correctly short message (Date, time, number, ... ). As soon as the answer is a bit longer, we won’t get it on WASM.
We are using the following code snippet:

#if __WASM__
            var innerHandler = new Uno.UI.Wasm.WasmHttpHandler();
#else
            var innerHandler = new HttpClientHandler();
#endif

   _httpClient = new HttpClient(innerHandler);
   var txt = await _httpClient.GetStringAsync(new Uri( "http://..."));

Any suggestions? We didn’t fin a running sample. So it would be nice to add one to the playground.

For which Platform:

  • iOS
  • Android
  • [X ] WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Windows
@ZeProgFactory ZeProgFactory added kind/contributor-experience triage/untriaged Indicates an issue requires triaging or verification labels May 26, 2020
@jeromelaban
Copy link
Member

Thanks for the report! Do you see any error message in the browser debug console ?

@jeromelaban jeromelaban added kind/bug Something isn't working triage/needs-information Indicates an issue needs more information in order to work on it. and removed kind/contributor-experience labels May 26, 2020
@ZeProgFactory
Copy link
Author

ZeProgFactory commented May 26, 2020

Thanks, Jerome, for pointing me in the right direction …

In fact, the transmission was fine in every case, but as we try to display the result with an MessageDialog the underlaying JavaScript interprets the text. So short texts or numbers worked fine, but JSON and some character sequences broke the MessageDialog …

So for everybody our working “test display”:

textBlock.Text = txt;
var dlg = new MessageDialog(txt.Length.ToString());
await dlg.ShowAsync();

A TextBlock has no problem digesting JSON, text , or other text snippets ...

Logs before the correction:
now - OK -localhost-1590528021608.log
TestDB - KO - localhost-1590527897147.log
data - KO - localhost-1590528054187.log
I18n - KO - localhost-1590527988804.log

@no-response no-response bot removed the triage/needs-information Indicates an issue needs more information in order to work on it. label May 26, 2020
@jeromelaban
Copy link
Member

Right! This is a case of invalid escaping inside of Uno in MessageDialog:

var command = $"Uno.UI.WindowManager.current.alert(\"{Content}\");";

The content should be escaped using WebAssemblyRuntime.EscapeJs :

public static string EscapeJs(string s)

@jeromelaban jeromelaban added good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. and removed triage/untriaged Indicates an issue requires triaging or verification labels May 27, 2020
@carldebilly
Copy link
Member

@jeromelaban Maybe a duplicate of #2501?

@ZeProgFactory
Copy link
Author

ZeProgFactory commented May 28, 2020

Regarding our basic problem: a UNO / WASM / WS sample we made one: https://github.com/ZeProgFactory/UNO.Sample.Webservice
Don't hesitate to ask for or add missing features, or give any feedback ...

GitHub
UNO sample app using a webservice . Contribute to ZeProgFactory/UNO.Sample.Webservice development by creating an account on GitHub.

@ZeProgFactory
Copy link
Author

@jeromelaban Maybe a duplicate of #2501?

@carldebilly you are right, but the issue and how to work around / correct it are better documented in this exchange. Other wise you should add @jeromelaban comments to the other issue.

@jeromelaban
Copy link
Member

Indeed, let's close this issue and get the other one fixed instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants