Need help getting started with GRPC dataportal #4840
-
|
Hey folks, I am working on a project that is still using a very old version of CSLA and I am researching a path forward for upgrading to the latest version. As a part of this effort, I am trying to build a basic GRPC data portal client/server proof of concept. I have a server project, a client project, and a business library with a single object. I've tried multiple configurations, but I always end up with the same error message during my tests. I have based my implementation on the SimpleNTier sample and the guidance provided in #2428. I'm sure I am missing something simple with configuration but I am not having any luck figuring it out on my own or searching for other examples. I'll provide all of the code for my proof of concept project. DataPortalServer - Program.cs using Csla.Channels.Grpc;
using Csla.Configuration;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGrpc();
builder.Services.AddCsla();
var app = builder.Build();
app.UseRouting();
app.MapGrpcService<GrpcPortal>();
app.Run();BusinessLibrary - Person.cs using Csla;
using Csla.Server;
namespace BusinessLibrary
{
[ObjectFactory(typeof(PersonFactory))]
[CslaImplementProperties]
public partial class Person : BusinessBase<Person>
{
public partial int Id { get; set; }
public partial string Name { get; set; }
}
}BusinessLibrary - PersonFactory.cs using Csla;
using Csla.Server;
namespace BusinessLibrary
{
public class PersonFactory(ApplicationContext applicationContext) : ObjectFactory(applicationContext)
{
public Person Fetch(int id)
{
var person = ApplicationContext.CreateInstanceDI<Person>();
using (BypassPropertyChecks(person))
{
person.Id = id;
person.Name = "Clark Kent";
}
MarkOld(person);
return person;
}
}
}DataPortalClient - Program.cs using BusinessLibrary;
using Csla;
using Csla.Configuration;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services
.AddCsla(csla => csla
.DataPortal(dp => dp
.AddClientSideDataPortal(c => c
.UseGrpcProxy(grpc => grpc
.DataPortalUrl = "http://localhost/grpc/dataportal"))));
var provider = services.BuildServiceProvider();
var applicationContext = provider.GetRequiredService<ApplicationContext>();
var portal = applicationContext.GetRequiredService<IDataPortal<Person>>();
int personId = 1;
// Deserialization exception occurs here.
var p = portal.Fetch(personId);
Console.WriteLine(p.Name);
Console.ReadLine();Any help will be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
|
After some further investigation, this issue seems to be specific to CSLA 10. My projects are targeting .net 9.0 because I do not currently have access to .net 10 for reasons beyond my control. This issue may simply be a backwards compatibility issue between CSLA 10 and .net 9.0. Downgrading the CSLA package references to 9.1.1 has allowed me to move forward. |
Beta Was this translation helpful? Give feedback.
-
|
Here's an extremely simple demo using the grpc data portal channel: |
Beta Was this translation helpful? Give feedback.
-
|
Also, when poking to find other areas where this issue may exist, I noticed that the Rabbit MQ portal has the same problem as the GRPC portal because it has the exact same However, the issue has been correctly addressed by the code in the HTTP portal which instead has two distinct methods for deserialization: private T? Deserialize<T>(byte[] data)
{
var deserializedData = _applicationContext.GetRequiredService<ISerializationFormatter>().Deserialize(data);
return (T?)deserializedData;
}
private T DeserializeRequired<T>(byte[] data)
{
return Deserialize<T>(data) ?? throw new SerializationException(Resources.ServerSideDataPortalRequestDeserializationFailed);
}My recommendation would be to change the GRPC portal and the Rabbit MQ portal to match the deserialization behavior of the HTTP portal. |
Beta Was this translation helpful? Give feedback.





Also, when poking to find other areas where this issue may exist, I noticed that the Rabbit MQ portal has the same problem as the GRPC portal because it has the exact same
Deserializemethod that is called in the same way.However, the issue has been correctly addressed by the code in the HTTP portal which instead has two distinct methods for deserialization: