C# gRPC service without proto file - c#

I'm looking for a way to communicate between different C# (only) apps via gRPC. Is there any way to provide service definitions and contracts by C# interfaces and POCO classes (attributed by ProtoMember, etc.), instead of creating a proto file and generating a code out of it? I need this to work on .net framework 4.7.2, i.e. working with grpc.core rather than grpc.dotnet.
PS: The main idea why I want this is to avoid the code generation part which seems to be excessive here. Also need to be able to specify custom attributes to my POCO classes, like DisplayAttribute and stuff.

Alright, looks like I found the answer https://github.com/grpc/grpc-dotnet/issues/68
protobuf-net.Grpc seems like the lib I was looking for

You can also check ServiceStack gRPC which provides code-first development.

Related

C#: Controllers in a re-usable library with the .net core framework

I've written all the classes and controllers for a web api to interact with a very large database (dozens of tables and controllers). I need to write a lot of small apps for specific tasks, as such, it would be idea if the controllers could also be a library file.
I've seen some old tutorials that suggest this is possible, but they no longer seem to work.
Could anyone please point me to somewhere that explains how this can be achieved; or, if there's a better best practices approach I should be taking.
Have all the object classes in their own library, and a working web app that interacts with the database. Want to extra the controllers into a library or include them in the existing object classes library.
By placing controllers in the library, do you mean having generic controllers so you can reuse them whenever you want for whatever model you need? Of so, you can check my library https://github.com/Ryukote/CoreGenerics which is also available on Nuget so you can add it to your project and use it as is.

Confused about protobuf-net WCF usage

I have been following this tutorial to add protobuf-net to my WCF project. I have a shared DTO library. Both server and Client use those DTO classes. I have attributed all my Service methods with [OperationContract] attributes, but i have not assigned any [DataContract] attributes on my DTO classes.
I added the protobuf-net Nuget package and added the configuration to the web.config.
I am using IIS Express to test my service, and thought that i should be ok with what i had done so far. However, after testing a few calls, i noticed that i forgot to add protobuf-net to my client and yet everything worked as expected (ie. no errors from serialization or deserialization).
I suspect that protobuf is not used in my program at all, and that i am missing something. I'd like to avoid using [DataContract] attributes but i could live with adding them, if that is what is need to get protobuf-net working.
What else am i missing?
A year ago I faced the same problem, where protoBuf seems to be an excellent option, with WCF it has some shortcomings.
I created an open source project to overcome these shortcomings, it uses protobu-net library and adds functionality to it, such that you don't need to share assemblies anymore with client. It however again requires you to put DataContract attributes though currently.
You can give it a try: https://github.com/maingi4/ProtoBuf.Wcf
DISCLAIMER: I am creator and owner of the above project.

Autogenerate C# WebApi from Models

Does anyone know of any tools that can generate a C# WebApi REST Interface for a model?
What I would like is to define my model and add attributes that describe properties of the resource in the context of standard REST architecture. After defining the model and adding attributes, the hypothetical tool would generate all the code needed for implementation.
I'm not 100% sure if this tool will work for your very specific case, but it is a code generator nonetheless and appears to be relatively versatile.
http://www.codesmithtools.com/product/generator
I'm assuming you already searched for a code generator to suit your need so if this one doesn't work for you, you may have to face the music and write one yourself.
A co-worker I work with here wrote a generator in C# that pulled schema/data structure info from a SQL database, took that info, and simply output C# code to a .cs file.
I know this isn't the best answer, but hopefully it helps in at least some way. :)
Use OData to create simple rest services(GET, POST, PUT, DELETE). OData is being widely accepted by many UI components which allow us to use dynamic querying at request level.
You can simply replace the Model Names and DTO Names in an odata controller to use it to other model's controller.

Generating Java data classes from C# data classes - is there an existing tool / method?

I'm writing a java client for a WCF REST service. This service uses lots of different data classes for communication, transmitted in JSON. On my side, I'm using the Gson lib to do handle the serialization of these classes. However for this to work, I obviously need the Java definitions of the used C# classes.
Currently I'm writing these by hand: I check the C# class definitions, check which property has a [DataMember] annotation and create a corresponding java class with those properties. This is a terrible solution: it's slow, tedious and difficult to keep these classes up to date manually.
What tools / method should I use to generate these classes somehow from their C# counterparts? Is writing some .net console app that generates java classes using reflection the only solution?
You can try a tool like wsdl4j to create a proxy java file and just use the class definitions in it.

Generate serializable classes from entity framework classes?

Here's my problem:
I am creating a Blackberry application that access's my data via a web service.
The web service is using entity framework which was created for my web application.
I use the SUN wireless toolkit stub generator to create the code and classes to access the web service from the Blackberry application. The stub generator does not like dates and fields that return collections so I usally have to create new classes manually that deal with this.
Idea:
I want to be able to generate these classes automatically from my entity framework model?
What is the best way to do this?
I would like to make this generic. Something similar to the POCO generator would be ideal
Thanks
From what I know about Entity Framework, it has some XML-based schema description. You can write relatively simple XSLT transformation, which will transform this XML into a set of classes suitable for transmitting over the wire.

Categories