C# GRPC - without dependencies [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
We're using GRPC extensively in a project, using the Grpc.Tools package to generate .Net clients from the .proto definition files. However, we have a headache in that the generated code is very tightly coupled with GRPC - it has GRPC specific attributes, GRPC specific interfaces and so on.
What I'm after is a way to generate "clean" interfaces in C#/.Net, i.e. plain C# types and interfaces to describe the service and messages, that can be cheaply referenced without bringing along all the GRPC stuff.
Are there any existing libraries/tools out there that you've had good experiences with? Or any example projects I can look at that deal with this issue neatly? Or perhaps an example of customising the GRPC tooling to extract what I'm after from it?

There are a few things to know here:
gRPC C# itself is serialization format agnostic (= you can use any serialization format you want), but because without a serialization format, the usability is limited, the Google Protocol buffers are supported as the default choice. The Grpc.Tools package provides the protocol buffer compiler plugin, which generates service stub that are to be used with Protobuf + gRPC (so the "tight coupling" you're mentioning is intended).
If you want to use your own serialization format, you basically need to write your own code generator (and gRPC C# API is designed in a way that this is possible) that will generate classes/interfaces that will look the way you want. In fact, if you inspect the Grpc.Core nuget package (the main functionality of gRPC C#), you'll see that it doesn't have any dependency on Google.Protobuf whatsoever, which allows you to use serialization format of choice. Please note that this is a pretty advanced concept and I would strongly recommend just using the default option (i.e. gRPC with prototobuf, using the standard codegen) unless you know what you are doing.
There are projects that have successfully implemented a custom codegen for different serialization formats such as Apache Thrift, Flatbuffers, Microsoft Bond etc. You can inspect their code to see how to write a custom codegen (there are also several blogposts around on this topic).

Currently, there are no such libraries. Even protobuf.net is not compatible with grpc (Using ProtoBuf-net with gRPC)
What I'm after is a way to generate "clean" interfaces in C#/.Net,
i.e. plain C# types and interfaces to describe the service and
messages, that can be cheaply referenced without bringing along all
the GRPC stuff.
That is the most significant advantage of the grpc that based on proto file code is generated in multiple languages. I agree with you that generated code could look better, and interfaces should be created for client/server/messages.
If you don't want to use generated code, then you can create your custom client implementation, other parts (server, messages) must be used from generated code.

Related

Which is better for my scenario - WCF or WebAPI? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
My case is - I'm developing a system that help a car service to communicate with their customers and vice versa. There will be two products - a mobile app written in Xamarin.Forms and a web page in ASP.Net - both doing same things more or less, an alternative. The database will be hosted on SQL Server. And now I'm confused about the "middle" layer. I have been reading a lot about WCF and WebAPI and I still can't figure out which is better for me. Any suggestions for this scenario?
"Better" is always a hard question to answer. So, that's my disclaimer.
WebAPI is currently pretty standard, and quite easy. It allows for simple REST api's - although these are very doable with WCF as well.
The main difference between WCF and Web API
Web API
is, well Web (HTTP) - almost every language supports it, it's relatively light weight.
WCF
It's big - HTTP is just one of the options for binding. It's ideal for enterprise wide connectivity solutions. For example - reusing your logic for HTTP bindings and or message queueing.
One nice feature of WCF is that, at least for C#, it generates client libraries and models for you. It comes with Visual Studio (note: see warning). For the WebAPI, you might need to create the client libraries yourself - which basically be a lot of HTTP calls.
If you want it simple - WebAPI has very good support and can be implemented easily from any language - the clients and models are pretty straight forward - but usually you do need to code them yourself, unless you use OpenAPI spec and some toolkits.
Warning
The generated WCF libraries, might or might not be compatible with the framework (Mono, Xamarin, Core, etc.) you are using. As #Dai mentions, the WCF client library generation might be outdated. Although I do not know if there are more open source tools available to extract clients from the WSDL. So, you should try if your client is compatible first.
For Web API client generation, you can look at tools like Swaggerhub. Do note: you need to define the spec in your application (or provide it explicitly)
See: https://swagger.io/tools/swaggerhub/
The advise (obviously just an opinion)
If you don't need the full package of WCF, the extensive binding capabilities and such, I would go for the WebAPI variant.
If you combine it with Swagger (OpenAPI spec), you'll get a pretty open and easy to use API available for a broad variety of languages.
For more info on swagger/swashbuckle: https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.1&tabs=visual-studio

How to Call Web Service Using SOAP Request with example? [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Background:
I am creating a webservices site which will provide many types of simple services over SOAP and possibly other protocols too. The goal is to make it easy to do for example conversions, RSS parsing, spam checks and many other types of work. The site will be targeted mostly at beginner developers.
My Problem:
I have never developed any C#, or .NET for that matter. I did hack some VB6 many years ago but that's it. Now I need some examples of doing RPC calls over SOAP in C#. I have tried to search the web, and Stack Overflow, to find this but didn't find many resources, and I have no idea how to rank the resources (which are old? which are incorrect? etc).
I have created a simple example service, which is called like this in PHP:
<?php
$client = new SoapClient('http://webservi.se/year'); //URL to the WSDL
echo $client->getCurrentYear(); //This method returns an integer, called "year"
?>
I now want to call this method as easily as possible in C#. All references and examples are very welcome. Where do I begin? Which classes/modules/whatever can I utilize?
The solution does not have to involve SOAP at all if there are better communication frameworks (the back end is meant to be extensible), but note that the server side is implemented in PHP on Unix so proprietary solutions from Microsoft are out of the question on the server side.
Note that I need this so I can write documentation possible for J. Random Web Developer to follow (even if they are on shared web hosting). I therefore think the best approach should be to do this in code only, but even other ways of doing this are of course welcome.
Prerequisites: You already have the service and published WSDL file, and you want to call your web service from C# client application.
There are 2 main way of doing this:
A) ASP.NET services, which is old way of doing SOA
B) WCF, as John suggested, which is the latest framework from MS and provides many protocols, including open and MS proprietary ones.
Adding a service reference step by step
The simplest way is to generate proxy classes in C# application (this process is called adding service reference).
Open your project (or create a new one) in visual studio
Right click on the project (on the project and not the solution) in Solution Explorer and click Add Service Reference
A dialog should appear shown in screenshot below. Enter the url of your wsdl file and hit Ok. Note that if you'll receive error message after hitting ok, try removing ?wsdl part from url.
I'm using http://www.dneonline.com/calculator.asmx?WSDL as an example
Expand Service References in Solution Explorer and double click CalculatorServiceReference (or whatever you named the named the service in the previous step).
You should see generated proxy class name and namespace.
In my case, the namespace is SoapClient.CalculatorServiceReference, the name of proxy class is CalculatorSoapClient. As I said above, class names may vary in your case.
Go to your C# source code and add the following
using WindowsFormsApplication1.ServiceReference1
Now you can call the service this way.
Service1Client service = new Service1Client();
int year = service.getCurrentYear();
I have done quite a bit of what you're talking about, and SOAP interoperability between platforms has one cardinal rule: CONTRACT FIRST. Do not derive your WSDL from code and then try to generate a client on a different platform. Anything more than "Hello World" type functions will very likely fail to generate code, fail to talk at runtime or (my favorite) fail to properly send or receive all of the data without raising an error.
That said, WSDL is complicated, nasty stuff and I avoid writing it from scratch whenever possible. Here are some guidelines for reliable interop of services (using Web References, WCF, Axis2/Java, WS02, Ruby, Python, whatever):
Go ahead and do code-first to create your initial WSDL. Then, delete your code and re-generate the server class(es) from the WSDL. Almost every platform has a tool for this. This will show you what odd habits your particular platform has, and you can begin tweaking the WSDL to be simpler and more straightforward. Tweak, re-gen, repeat. You'll learn a lot this way, and it's portable knowledge.
Stick to plain old language classes (POCO, POJO, etc.) for complex types. Do NOT use platform-specific constructs like List<> or DataTable. Even PHP associative arrays will appear to work but fail in ways that are difficult to debug across platforms.
Stick to basic data types: bool, int, float, string, date(Time), and arrays. Odds are, the more particular you get about a data type, the less agile you'll be to new requirements over time. You do NOT want to change your WSDL if you can avoid it.
One exception to the data types above - give yourself a NameValuePair mechanism of some kind. You wouldn't believe how many times a list of these things will save your bacon in terms of flexibility.
Set a real namespace for your WSDL. It's not hard, but you might not believe how many web services I've seen in namespace "http://www.tempuri.org". Also, use a URN ("urn:com-myweb-servicename-v1", not a URL-based namespace ("http://servicename.myweb.com/v1". It's not a website, it's an abstract set of characters that defines a logical grouping. I've probably had a dozen people call me for support and say they went to the "website" and it didn't work.
</rant> :)
If you can get it to run in a browser then something as simple as this would work
var webRequest = WebRequest.Create(#"http://webservi.se/year/getCurrentYear");
using (var response = webRequest.GetResponse())
{
using (var rd = new StreamReader(response.GetResponseStream()))
{
var soapResult = rd.ReadToEnd();
}
}
Take a look at "using WCF Services with PHP". It explains the basics of what you need.
As a theory summary:
WCF or Windows Communication Foundation is a technology that allow to define services abstracted from the way - the underlying communication method - they'll be invoked.
The idea is that you define a contract about what the service does and what the service offers and also define another contract about which communication method is used to actually consume the service, be it TCP, HTTP or SOAP.
You have the first part of the article here, explaining how to create a very basic WCF Service.
More resources:
Using WCF with PHP5.
Aslo take a look to NuSOAP. If you now NuSphere this is a toolkit to let you connect from PHP to an WCF service.
You're looking in the wrong place. You should look up Windows Communication Framework.
WCF is used both on the client and on the server.
Here you can find a nice tutorial for calling a NuSOAP-based web-service from a .NET client application. But IMO, you should also consider the WSO2 Web Services Framework for PHP (WSO2 WSF/PHP) for servicing. See WSO2 Web Services Framework for PHP 2.0 Significantly Enhances Industry’s Only PHP Library for Creating Both SOAP and REST Services. There is also a webminar about it.
Now, in .NET world I also encourage the use of WCF, taking into account the interoperability issues. An interoperability example can be found here, but this example uses a PHP-client + WCF-service instead of the opposite. Feel free to implement the PHP-service & WFC-client.
There are some WCF's related open source projects on codeplex.com that I found very productive. These projects are very useful to design & implement Win Forms and Windows Presentation Foundation applications: Smart Client, Web Client and Mobile Client. They can be used in combination with WCF to wisely call any kind of Web services.
Generally speaking, the patterns & practices team summarize good practices & designs in various open source projects that dealing with the .NET platform, specially for the web. So I think it's a good starting point for any design decision related to .NET clients.

.NET, JSON, Embedded, Free Commercial-Use data management solution? What to do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am trying to develop a data management solution for a commercial product that meets several criteria. The criteria and my reasoning are as follows:
The solution should be in C# or support C#
Manage data as JSON
No external schema maintenance
Be able to cache some or all data in memory and persist to disk
Not require an additional installation
If the solution involves third-party software, the license must support no-cost commercial use
Requirement #1: My application is written in C# and I would prefer that any solution does not involve integrating with applications, libraries, or code in another language.
Requirement #2: There are several JSON-based tools and libraries that I would like to utilize, so I need a solution where data is either in or easily converts to/from JSON.
Requirement #3: I want to avoid the schema maintenance that comes with using relational database solutions. I prefer to manage mismatched data-to-object mappings in code and have code update older data instead of managing schema updates separately.
Requirement #4: I require some or all data to be loaded into memory at all times, and all data to be persisted to disk. Whether data persists in memory or not should be optional per data type.
Requirement #5: When installing my product I don't want to have any secondary installations or have any external services running other than my application. A completely self-contained solution is best.
Requirement #6: The intended use is for a distributed commercial product. I would prefer to avoid any additional fees or licensing issues that come with many third-party solutions.
To date I have tried several solutions. Originally I did not have as many constraints and went with a SQLite.NET and its use wasn't unpleasant, but the overhead from schema maintenance and data format was more than I would like. I investigated a lot of NoSQL solutions (such as RavenDB), other third-party solutions (Karvonite), and simple JSON file storage implementations, but I'm not satisfied with any of them.
Is there a custom approach or solution that I am missing, that someone else has used successfully? I'm hoping that I am simply overlooking the option(s) that I am after, and that some NoSQL and .NET experts out there have enough experience in this area to point me in the right direction.
EDIT: In case any original commentators are confused, I updated the question and title to better adhere to SO's policies.
Fluent NHibernate Automapping on top of SQLite would meet all your requirements except edit #2 - "NoSQL, preferably all data is a JSON document"
It automaps a relational DB schema from your object model...does not use JSON. edit You might be able to save JSON data as BLOB, however. (caveat: I know almost nothing about JSON)
Have you taken a look at the Karvonite Framework? The Karvonite Framework provides a strongly-typed embedded database system that includes a portable library implementation for .NET / Windows Store / Silverlight / Windows Phone / Xbox development. I have only used this for small database implementations but so far it has met every one of my needs.

SOAP client in .NET - references or examples? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
Background:
I am creating a webservices site which will provide many types of simple services over SOAP and possibly other protocols too. The goal is to make it easy to do for example conversions, RSS parsing, spam checks and many other types of work. The site will be targeted mostly at beginner developers.
My Problem:
I have never developed any C#, or .NET for that matter. I did hack some VB6 many years ago but that's it. Now I need some examples of doing RPC calls over SOAP in C#. I have tried to search the web, and Stack Overflow, to find this but didn't find many resources, and I have no idea how to rank the resources (which are old? which are incorrect? etc).
I have created a simple example service, which is called like this in PHP:
<?php
$client = new SoapClient('http://webservi.se/year'); //URL to the WSDL
echo $client->getCurrentYear(); //This method returns an integer, called "year"
?>
I now want to call this method as easily as possible in C#. All references and examples are very welcome. Where do I begin? Which classes/modules/whatever can I utilize?
The solution does not have to involve SOAP at all if there are better communication frameworks (the back end is meant to be extensible), but note that the server side is implemented in PHP on Unix so proprietary solutions from Microsoft are out of the question on the server side.
Note that I need this so I can write documentation possible for J. Random Web Developer to follow (even if they are on shared web hosting). I therefore think the best approach should be to do this in code only, but even other ways of doing this are of course welcome.
Prerequisites: You already have the service and published WSDL file, and you want to call your web service from C# client application.
There are 2 main way of doing this:
A) ASP.NET services, which is old way of doing SOA
B) WCF, as John suggested, which is the latest framework from MS and provides many protocols, including open and MS proprietary ones.
Adding a service reference step by step
The simplest way is to generate proxy classes in C# application (this process is called adding service reference).
Open your project (or create a new one) in visual studio
Right click on the project (on the project and not the solution) in Solution Explorer and click Add Service Reference
A dialog should appear shown in screenshot below. Enter the url of your wsdl file and hit Ok. Note that if you'll receive error message after hitting ok, try removing ?wsdl part from url.
I'm using http://www.dneonline.com/calculator.asmx?WSDL as an example
Expand Service References in Solution Explorer and double click CalculatorServiceReference (or whatever you named the named the service in the previous step).
You should see generated proxy class name and namespace.
In my case, the namespace is SoapClient.CalculatorServiceReference, the name of proxy class is CalculatorSoapClient. As I said above, class names may vary in your case.
Go to your C# source code and add the following
using WindowsFormsApplication1.ServiceReference1
Now you can call the service this way.
Service1Client service = new Service1Client();
int year = service.getCurrentYear();
I have done quite a bit of what you're talking about, and SOAP interoperability between platforms has one cardinal rule: CONTRACT FIRST. Do not derive your WSDL from code and then try to generate a client on a different platform. Anything more than "Hello World" type functions will very likely fail to generate code, fail to talk at runtime or (my favorite) fail to properly send or receive all of the data without raising an error.
That said, WSDL is complicated, nasty stuff and I avoid writing it from scratch whenever possible. Here are some guidelines for reliable interop of services (using Web References, WCF, Axis2/Java, WS02, Ruby, Python, whatever):
Go ahead and do code-first to create your initial WSDL. Then, delete your code and re-generate the server class(es) from the WSDL. Almost every platform has a tool for this. This will show you what odd habits your particular platform has, and you can begin tweaking the WSDL to be simpler and more straightforward. Tweak, re-gen, repeat. You'll learn a lot this way, and it's portable knowledge.
Stick to plain old language classes (POCO, POJO, etc.) for complex types. Do NOT use platform-specific constructs like List<> or DataTable. Even PHP associative arrays will appear to work but fail in ways that are difficult to debug across platforms.
Stick to basic data types: bool, int, float, string, date(Time), and arrays. Odds are, the more particular you get about a data type, the less agile you'll be to new requirements over time. You do NOT want to change your WSDL if you can avoid it.
One exception to the data types above - give yourself a NameValuePair mechanism of some kind. You wouldn't believe how many times a list of these things will save your bacon in terms of flexibility.
Set a real namespace for your WSDL. It's not hard, but you might not believe how many web services I've seen in namespace "http://www.tempuri.org". Also, use a URN ("urn:com-myweb-servicename-v1", not a URL-based namespace ("http://servicename.myweb.com/v1". It's not a website, it's an abstract set of characters that defines a logical grouping. I've probably had a dozen people call me for support and say they went to the "website" and it didn't work.
</rant> :)
If you can get it to run in a browser then something as simple as this would work
var webRequest = WebRequest.Create(#"http://webservi.se/year/getCurrentYear");
using (var response = webRequest.GetResponse())
{
using (var rd = new StreamReader(response.GetResponseStream()))
{
var soapResult = rd.ReadToEnd();
}
}
Take a look at "using WCF Services with PHP". It explains the basics of what you need.
As a theory summary:
WCF or Windows Communication Foundation is a technology that allow to define services abstracted from the way - the underlying communication method - they'll be invoked.
The idea is that you define a contract about what the service does and what the service offers and also define another contract about which communication method is used to actually consume the service, be it TCP, HTTP or SOAP.
You have the first part of the article here, explaining how to create a very basic WCF Service.
More resources:
Using WCF with PHP5.
Aslo take a look to NuSOAP. If you now NuSphere this is a toolkit to let you connect from PHP to an WCF service.
You're looking in the wrong place. You should look up Windows Communication Framework.
WCF is used both on the client and on the server.
Here you can find a nice tutorial for calling a NuSOAP-based web-service from a .NET client application. But IMO, you should also consider the WSO2 Web Services Framework for PHP (WSO2 WSF/PHP) for servicing. See WSO2 Web Services Framework for PHP 2.0 Significantly Enhances Industry’s Only PHP Library for Creating Both SOAP and REST Services. There is also a webminar about it.
Now, in .NET world I also encourage the use of WCF, taking into account the interoperability issues. An interoperability example can be found here, but this example uses a PHP-client + WCF-service instead of the opposite. Feel free to implement the PHP-service & WFC-client.
There are some WCF's related open source projects on codeplex.com that I found very productive. These projects are very useful to design & implement Win Forms and Windows Presentation Foundation applications: Smart Client, Web Client and Mobile Client. They can be used in combination with WCF to wisely call any kind of Web services.
Generally speaking, the patterns & practices team summarize good practices & designs in various open source projects that dealing with the .NET platform, specially for the web. So I think it's a good starting point for any design decision related to .NET clients.

What other alternatives to log4net logging exist? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
(subjective)
I'm looking for what your using to perform logging in your application. This log4net thing is giving me headaches. Is there a better answer out there or is everone just homebrewing a solution? I know the System.Diagnostics.Trace subsystem is quite capable should I layer on this?
NLog is probably the other big player in this area. Also, There is an application bloc in entreprise library that is dedicated to tracing and logging.
Why not use just the .NET classes for logging?
With Custom-Listeners you can do almost anything for logging, can apply filters, spread your logs to multiple targets, databases, files, network, whatever.
Just watch out what the .NET-Framework is capable of, you'll be surprised.
There are quite a few .NET logging libraries and tools out there, here's an extensive list:
http://www.dotnetlogging.com/
You might also want to take a look at our .NET logging product SmartInspect, which provides rich logging capabilities (in contrast to the text-only logging features of most other logging tools) and comes with a log viewer and optional log server application.
Try Elmah its pretty easy, mind you log4net is not so bad once you get your head into it....
What actually are your headaches?
We use the Enterprise Library exclusively in our corporate environment (Logging Block). And I've recently started to use Log4Net on personal projects.
From experience, the Enterprise Library, albeit powerful, is a mighty pain to get up and running. Not only from just trying to figure out which dll's to use, but the configuration can become unwieldy.
On the flip side, I've found Log4Net to be extremely easy and you can be up and running in no time; quite literally in less than an hour.
Granted I'm a MS fanboy (ok, not really, but they are the reason I can make a living) and typically go with MS. However, I've made the recommendation to migrate to Log4Net at work. The simplicity of it really is refreshing.
Take a look at Common.Logging. It works with all major logging frameworks (system.diagnostics, log4net, nlog, entreprise library) and allows you to switch logging frameworks from configuration.
From my personal experience - I've used .NET tracing in a corporate environment which didn't allow us to use opensource, and after we perfected the rolling file tracelistener, it was quite easy to use. Now I use log4net and it's pretty nice, but takes some getting used to.
I know this question is too old and you are looking for alternative to log4net, but believe me log4net is the best logging solution and is most commonly used and also provides large range of log listeners than any other logging framework. Moreover you can even implement a custom appender along with the in-built appenders. For those who are having trouble configuring log4net can use following post which describes step by step guide to make it work.
Log4Net section in Web.Config generates Error
happy logging:)

Categories

Resources