RavenDB Client in Blazor Webassembly (no hosted)

171 views
Skip to first unread message

Alejandro Estepa S.

unread,
Jun 4, 2020, 3:46:42 PM6/4/20
to RavenDB - 2nd generation document database
Hello,

I have tried an example of blazor wasm (NO HOSTED only WebAssembly) by making a REST API call to GET a document (I have achieved it by installing a plugin called "Allow CORS" in chrome that is in charge of adding the corresponding headers to the response, I have looked for the configuration option of "Raven / AccessControlAllowMethods" but I can't find it for the latest version of raven 4.2, I work in linux and there is no documentation to do it.) 
Now I see that ravendb client is .netstandard 2.1 and I have tried to GET a document in my project webassembly again, but it gives me an error when creating the requestexecutor in opensession. Is there a way to pass the httpclient instance of the dependency injection? I think that it would be great to be able to create a complete only WebAssembly application with access to the database.

Thanks in advance.

Oren Eini (Ayende Rahien)

unread,
Jun 7, 2020, 7:14:14 AM6/7/20
to ravendb
I'm not sure what you are trying to do.

CORS setup is here:

We don't provide a way to create the HttpClient externally, but I'm not sure what it is that you are trying to do 

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/7dc9ca3e-e299-499a-b1cb-7a17c91017a8%40googlegroups.com.


--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net
  

Alejandro Estepa S.

unread,
Jun 11, 2020, 2:19:03 PM6/11/20
to RavenDB - 2nd generation document database
Hi Oren Eini,
I am trying to create a webassembly application written in c # using blazor. My idea is to create a complete application, without a backend. I really like ravendb and since it has an api rest I want to work with it (similar to https://blog.jeremylikness.com/blog/ef-core-and-cosmosdb-with-blazor-webassembly/). The first thing I did was a simple rest call "response = await Http.GetStringAsync (" http: // localhost: 8080 / databases / Northwind / docs ")", but this gave me a CORS error in the browser. I looked at the link to the source code you included in your answer, but I still don't understand how it is configured: is there a key in settings.json for this? Could you give me an example? My ravendb server runs on docker. As I mentioned in my first post, I fixed this using a browser plugin that injects the response with the necessary values ​​for CORS, and this worked. Afterwards, I have used ravendb client nuget, but when running inside the browser in a sandbox, we have restrictions, such as accessing the "httpcliendhan¡dler.ClientCertificates" property which is not supported in webassembly. Do you think I could get ravendb client working in webassembly? Could you give me an example?

Thanks in advance.


El domingo, 7 de junio de 2020, 13:14:14 (UTC+2), Oren Eini escribió:
I'm not sure what you are trying to do.

CORS setup is here:

We don't provide a way to create the HttpClient externally, but I'm not sure what it is that you are trying to do 

On Thu, Jun 4, 2020 at 10:46 PM Alejandro Estepa S. <aes...@gmail.com> wrote:
Hello,

I have tried an example of blazor wasm (NO HOSTED only WebAssembly) by making a REST API call to GET a document (I have achieved it by installing a plugin called "Allow CORS" in chrome that is in charge of adding the corresponding headers to the response, I have looked for the configuration option of "Raven / AccessControlAllowMethods" but I can't find it for the latest version of raven 4.2, I work in linux and there is no documentation to do it.) 
Now I see that ravendb client is .netstandard 2.1 and I have tried to GET a document in my project webassembly again, but it gives me an error when creating the requestexecutor in opensession. Is there a way to pass the httpclient instance of the dependency injection? I think that it would be great to be able to create a complete only WebAssembly application with access to the database.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rav...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Jun 21, 2020, 7:39:21 AM6/21/20
to ravendb
There should be no configuration. It should just work.
Can you show the actual interactions from Blazor to RavenDB? It should indicate the CORS initial requests.

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/44aee5b5-41a6-42e7-9eeb-2ec7be3ebb90o%40googlegroups.com.

Kamran Ayub

unread,
Jun 28, 2020, 9:49:34 PM6/28/20
to RavenDB - 2nd generation document database
If you have a sample that would be awesome to see.

For localhost requests, the browser won't automatically add CORS headers. When you are using fetch, you can add "mode: 'cors'" to the options explictly, see MDN. For Blazor/C#, I am not sure how to do this but there's probably a way...

Kamran Ayub

unread,
Jun 28, 2020, 9:50:55 PM6/28/20
to RavenDB - 2nd generation document database


On Sunday, June 28, 2020 at 8:49:34 PM UTC-5, Kamran Ayub wrote:
If you have a sample that would be awesome to see.

For localhost requests, the browser won't automatically add CORS headers. When you are using fetch, you can add "mode: 'cors'" to the options explictly, see MDN. For Blazor/C#, I am not sure how to do this but there's probably a way...

You could test this theory locally, by using making a hosts entry to use a fake DNS name, then trying to do it. The browser should consider it a cross-origin request and use CORS. 
Reply all
Reply to author
Forward
0 new messages