dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.55k stars 25.31k forks source link

How to generate proxies? #18747

Closed Thorium closed 2 years ago

Thorium commented 4 years ago

How do I set hubConfig to EnableJavaScriptProxies true?


Document details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Thorium commented 4 years ago

It was so convenient to use the Hubs with Typescript in AspNet.SignalR with EnableJavaScriptProxies (...or you could have generate the proxies manually with signalr.exe):

// Typescript types:
interface ISignalHub extends SignalR { SignalHub : any; }
$.connection.hub.url = "/signalr";
(<ISignalHub>$.connection).SignalHub.server
   .myServerMethod("some parameter").done(function (result) {
        // it just works!
    });

Compare the AspNetCore version, so much wizzard-walkthrough, and still not showing is it possibe to call a Hub server side method:

https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr-typescript-webpack?view=aspnetcore-2.1&tabs=visual-studio

BrennanConroy commented 3 years ago

There is no equivalent to proxies in ASP.NET Core.

The same code in ASP.NET Core SignalR would look like:

connection.invoke("myServerMethod", "some parameter")
    .then(function (result) {
        // code
    });

The walkthrough shows calling a method on the server in https://docs.microsoft.com/aspnet/core/tutorials/signalr-typescript-webpack?view=aspnetcore-2.1&tabs=visual-studio#enable-client-and-server-communication-1

bradygaster commented 2 years ago

Closing this per @BrennanConroy's reply.