MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

Multiple Data Portals #583

Open johntco opened 6 years ago

johntco commented 6 years ago

I have a need for a Windows Service data portal. Can the Windows Service be on a remote machine relative to the client app?

Also, if it needs to be local, can there be dataportal chaining, meaning that one dataportal connects to another dataportal, etc.?

I would need this because I have client apps that are on a private network and only have access to a back-end server (not the internet), and that back-end server would then proxy the requests through the dataportal to an HttpDataPortal that is on the internet, for request processing. Does that make sense, and is it possible?

tfreitasleal commented 6 years ago

Can the Windows Service be on a remote machine relative to the client app?

Yes it can. On Desktop applications that would be the (about) only solution.

can (...) one dataportal connects to another dataportal,

Yes it can. I think it's on the e-books:

It looks like your case it's a bit the opposite but it's still possible.

rockfordlhotka commented 6 years ago

The data portal can be hosted anywhere you can expose an endpoint of some sort. If your endpoint is http or WCF you can use the existing channels (proxy/host combos), but you can always create your own proxy/host if you need something like raw TCP or something.

So yes, you can host in a Windows Service.

Whether the service needs to be on the same computer or a different one is a network routing issue, having nothing to do with CSLA. Obviously the client machine needs to be able to have a valid address to the Windows Service endpoint, and there can't be any firewalls or NAT routers blocking traffic.

If the client machine can ping the "server" you are probably going to be successful.

Your second question about data portal chaining has a "yes, but" answer. To support chaining you'll need to create a custom data portal host that has some understanding of your rules about when to invoke the data portal locally or remotely.

Years ago, when Silverlight was a thing, CSLA did have a pass-through data portal designed specifically to support Silverlight clients that needed to have data portal calls pass through the web server to an app server. That's no longer in the framework, but you can see the code in the 3.8 branch.

johntco commented 6 years ago

What would you think would be a good configuration for this then? I have a client that only has access to a server, and that server can access the internet. However, that server does not have access to the db directly over the internet, so it would need to connect to a hosted service (HttpDataPortal) that does.

rockfordlhotka commented 6 years ago

Your original train of thought seems totally valid to me.

It sounds like the client can access the server, so there's network routing to the server from the client right? You can host the data portal in a Windows Service on that server and reach it from the client.

You'll need to write your own custom host in any case because the hosts provided by CSLA assume they'll run in ASP.NET. So when you write your custom host, just write it as a pass-through and have it call the "real" data portal server.

johntco commented 6 years ago

Is that similar to overriding the PostAsync in the HttpDataPortal… but I would be overriding "something" in the WindowService to make an HttpClient call to the public HttpDataPortal, then sending THAT response back to the client?

public async override System.Threading.Tasks.Task<HttpResponseMessage> PostAsync(string operation)
{
    var data = await base.PostAsync(operation).ConfigureAwait(false);
    return data;
 }