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
Related
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.
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.
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 8 years ago.
Improve this question
i got a project where i must create à web application based on ASP.NET (C#), i need to generate dynamic statistic into a dashboard, the data is extracted from the database. the user can export to XML or CSV file. My database is on SQLserver express 2014 and i m using visual studio 2013.
Looking for advice, what sort of technology to study .
thanks.
Dali, you haven't mentioned if you need to use MVC or WebPages for your project so I will assume it's MVC. However, you can apply the same steps to WebPages with slight modifications.
There are MANY ways to build a dashboard in ASP.Net. Each has its own pros and cons. Please, use your own judgement. This list is nowhere near complete so I would recommend to search possible options online.
1. SSRS Dashboard
Many developers think it's an outdated technology, and, while I agree with them, I still think it's worth to learn if you're trying to implement Reports repository with basic functionality (daily snapshots, parameter filtering, report scheduling). SSRS supports different formats like Excel, HTML, XML, PDF. It's easy to learn and very intuitive. It uses Visual Basic for scripting, and can be easily integrated in .ASPX web pages.
Take a look at some examples.
2. R + MVC
This is a good option for the statistical dashboard. I personally have no experience using R so I cannot tell for sure if it's a viable option in your case. However, it's something to consider when you do your research. Here is a good example to get an idea.
3. JavaScript Chart Library + MVC
Here is good a example. For the JavaScript library, you can use either D3 or HighCharts. Both are great and powerful. Both can be easily integrated with .Net framework. Also, this option is recommended if you already know the JavaScript. There is no need to learn anything else.
4. AnjularJS (or any other JS framework) + MVC (or RESTful API)
This one is my favorite because it provides a lot of room for customization and is flexible enough to satisfy your client needs. Some developers avoid using MVC and replace it with WebAPI (or even SignalR). This also a great solution and allows you to reuse the code if you decide to build a public API based on your dashboard data in real time. Here is what I'm talking about.
P.S. In all these options, SQL Server is used as a main data storage that is why I decided not to include it everywhere. Since you are a .Net developer, it's an obvious choice that you stick with SQL Server, in my opinion.
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 4 years ago.
Improve this question
In Java I've been able to embed* the jetty server in my apps, but is there an equivalent embedded* server technology for .Net?
Open source (FLOSS) would be preferred if possible.
*by embedded I mean a lightweight web server app that could be packaged with my application and run on a user's local desktop machine to provide a web service locally.
The closest equivalent to Jetty I've found so far is Nancy, described as:
a lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono.
Nancy is designed to handle DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH requests
Nancy was designed to not have any dependencies on existing frameworks. Built with the .NET framework client profile, Nancy can be used pretty much wherever you want to, since it’s completely self contained with it’s own request and response objects.
One of the core concepts in Nancy is hosts. A host acts as an adaptor for a hosting environment and Nancy, thus enabling Nancy to run on existing technologies such as ASP.NET, WCF and OWIN, or integrated in any given application.
An even more lightweight option is Kayak (Update: project looks dead as of 2014-01-18), which its documentation describes as:
a simple web server. It listens for connections, creates an in-memory representation of requests, and allows you to easily generate responses. It can be used in any C# program. Your code loads Kayak into its process space—not the other way around!
and both Nancy and Kayak are MIT licensed.
Here's another alternative I wrote last year and and has served me well.
EmbedIO: https://github.com/unosquare/embedio
I use it mostly to create RESTful services on the Raspberry Pi (soft-float).
Edit: Updated code for Mono 3.10, support for WebSockets, and Asynchronous handling of requests.
Update for 2016:
The new kid on the block is Kestrel.
Kestrel is an open source web server that is a part of the ASP NET Core initiative by Microsoft. It is an event based webserver built upon libuv (it basically node.js - js + .net). This means that it should be easily portable between different operating system. Unfortunately, it does mean it requires an external native dependency. *
https://github.com/aspnet/KestrelHttpServer
An older project that does this is Nowin
https://github.com/Bobris/Nowin/tree/master/Nowin
This is an implementation of Owin built entirely within .net. Unfortunately, it has been deprecated in favor for Kestrel.
Edit: * The newest version of Kestrel has dropped libuv for a managed dotnet socket approach. This of course means Kestrel no longer has a native dependency.
The one that is used with Visual Studio is called cassini. There is a good derivative called UltiCassini.
The solution from Microsoft itself is called Katana,
https://katanaproject.codeplex.com/
Note that it is fully open sourced, under Apache license.
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.