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

Getting query string parameters with asp.net core. #335

Open
Dawiducik opened this issue Jun 21, 2021 · 4 comments
Open

Getting query string parameters with asp.net core. #335

Dawiducik opened this issue Jun 21, 2021 · 4 comments

Comments

@Dawiducik
Copy link

Dawiducik commented Jun 21, 2021

Hello,
My goal is to connect to Caller with path e.g. ws://localhost:8081/ws, but I want to provide additional GET paramer to URL (so it becomes more like ws://localhost:8081/ws/<resource-id>) and e.g. reject the connection. My question is, is it possible in current state of this library? Is there any DI service containing context? Maybe I can use HttpContext in handlers? Should I make my own workaround, or use WAMP host in controller method taking GET params?
Thanks in advance!

@darkl
Copy link
Member

darkl commented Jun 21, 2021

This is how setting up WampSharp in ASP.NET Core looks like:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    WampHost host = new WampHost();

    app.Map("/ws", builder =>
    {
        builder.UseWebSockets();

        host.RegisterTransport(new AspNetCoreWebSocketTransport(builder),
                               new JTokenJsonBinding(),
                               new JTokenMsgpackBinding());
    });

    host.Open();
}

Since you pass the builder to the AspNetCoreWebSocketTransport ctor, you are able to modify it beforehand and for instance do some address filtering there. Does that help with your question?

Elad

@Dawiducik
Copy link
Author

Well, not really, I know how to configure and register "Caller" or "Calee" but I still can't figure out how to retrieve query parameters from http context in the way like you did in the example.

@darkl
Copy link
Member

darkl commented Jun 22, 2021 via email

@Dawiducik
Copy link
Author

First of all I think I misled you a little bit, I want to expose CALLEE, not CALLER.

So lets assume that I have super simple service ping-ponging the server and client.

public interface IArgumentsService
{
    [WampProcedure("com.arguments.ping")]
    string Ping();
}

public class ArgumentsService : IArgumentsService
{
    public string Ping()
    {
        return "pong";
    }
}

And my Startup.cs looks like this:

var wampHost = new WampHost();
app.Map("/ws/<id>", async builder =>
{
    builder.UseWebSockets();
    var realm = wampHost.RealmContainer.GetRealmByName("realm1");
    var instance = new ArgumentsService();
    await realm.Services.RegisterCallee(instance);
    // Get "id" from query string, but how?
    // Accept the connection, but send the error based on resource id.
    wampHost.RegisterTransport(new AspNetCoreWebSocketTransport(builder),
                        new JTokenJsonBinding(),
                        new JTokenMsgpackBinding());
});
wampHost.Open();

How may I achieve this?
And the second thing, how may I attach the WAMP host to a different service through DI, and send the message to specific websocket connected with given id?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants