Real time data from VB.net app to web server - vb.net

I'm fairly new to VB.net programming. I'd like some suggestions for methods/procedures for sending real time data from a VB.net app to a web server (asp.net) for real time display. My question relates to the best method to send the data from the desktop app and the best way to receive and handle the data on the server. I'm not asking for sample code, just some idea of what methods to research. I am currently using a text file upload method but I'm sure there is a more efficient way of achieving this. Thanks in advance for your help.

For sending data to the server, you may research about webservice or WCF.
http://en.wikipedia.org/wiki/Web_service
http://msdn.microsoft.com/en-us/netframework/dd939784
For retrieving data from the server to your ASP.Net application, you can research about AJAX.
http://www.w3schools.com/ajax/default.asp
http://api.jquery.com/jQuery.ajax/

If you are using the MVC framework for ASP.NET (which I strongly recommend over WebForms), MVC4 which has recently gone into RC mode features a very nice new web API:
http://www.asp.net/web-api
"ASP.NET MVC 4 includes ASP.NET Web API, a new framework for creating HTTP services that can reach a broad range of clients including browsers and mobile devices. ASP.NET Web API is also an ideal platform for building RESTful services."
It allows you to define quite simple methods on the server which work directly with your actual domain objects and it does the work of returning data in an appropriate content type (e.g. JSON, XML) based either on the incoming request or a specific configuration you may set.
Your web app could then poll the GET methods on the same API controller class via Ajax (jQuery is nice) to display the results.

Related

Best way to post to a .Net Core Web API

I created a Web API with .Net Core.
I currently have the form from the .cshtml page posting through to a normal MVC controller and then using the HTTP Post method to post to the Web API endpoint.
Is it better to post directly from the form on the .cshtml to the WebApi endpoint?
I'm relatively new so not sure which is better.
Imho the current approach is correct: you post some data to a controller inside your application and then do stuff with this data (in this case sending them back to a Web API).
Why is correct? Because you can do all sort of checks inside the controller before sending any data to the Web API (like data validation, transformations, composition etc...). Also, I'm not sure if you can post directly to a Web API using Blazor methods for posts. To do that I think you have to write the form using plain HTML and than detect the submit event using Javascript, where you finally post the form data to the Web API. But again, I think the current approach is good (if not optimal)
it's not a bad solution by any means but if your API is publicly accessible (not just from your web project with the mvc controllers) I would suggest posting directly to the API.
Posting directly to the API reduces roundtrips. And also the validation and everything should be handled by the API.
Use Web APIs when you want to deal with data or HTTP status codes only, i.e. not expecting HTML to be returned. Typical use cases from a web perspective are doing any asynchronous communication through Javascript (native JS, Vue, Angular, React, JQuery, etc....)
If you expect HTML to be returned, use MVC or whatever view framework you want to use. In this case it is perfectly fine to call other APIs from the MVC controller.

Should we call Web API from MVC application in same solution?

I am working on a project in MVC that has mobile application so one thing is clear that we have to use Web API so it can used in mobile application.
After creating API when we started to develop Web site we are confused and had discussion on whether to use API or directly access to the Business object. And we ended up after having opinion form more experienced developer to consume Web API instead of using Business object directly.
I'm having confusion regarding to this solution structure.
1) Why we should use Web API and make HTTP request (which is time consuming) to get or put data instead of business object directly which is in same solution.
2) After having arguments they said what if client wants to host API and web on different cloud server and apply scaling only on API or may be he want to have different url for accessing API and Web (which is some what logical). So in that case should we call Web API from MVC application in same solution?
3) If we're hosting API and Web on different hosting so it means our Web will use WebClient and have HTTP call on each navigation. Is it right?
4) If we'll business object form both API and Web hosting on different server then if something change in BL will need to update build on both server.
5) Or we should create only one project for API and can add views or html pages to develop Web interface so in that way we can directly call API from ajax.
As per my knowledge #5 is the best solution or API is only for 3rd party access. If we have DB, EF, data layer and business layer in same solution then we should not use API to make HTTP calls and directly access business object. (correct me if I'm wrong)API is needed when mobile application or desktop or any one want to access application so we can have same repository and data layer.
In my scenario I've to create API as we also have mobile application, and in project API side we called business layer (separate project) and business layer communicate to data access layer (separate project). So my question is if we host our API and web to different servers then calling API which is a HTTP request may take longer rather than using method from business layer as we create the project and we've .dll of business layer. In API controller we just convert out put of our business to json format.
I've searched on internet but didn't get convincing answer. I've found a blog http://odetocode.com/blogs/scott/archive/2013/07/01/on-the-coexistence-of-asp-net-mvc-and-webapi.aspx discussing same point but again in that blog my question is why we need to consider scenario #3?
I think you have answered your own question in writing, but really this boils down entirely to what your requirements are, and perhaps more importantly, what the strategy for your application is.
First of all, using Web Api over accessing Business Objects directly (by which I think you mean through viewmodels etc) only makes sense if you are controlling access of data client side.
If you only have a requirement for consuming data from client side within a particular application, then hosting Web API within the same project makes sense. Sometimes, for instance when building a SPA or rich-client web app, then using Web Api within the same projhect is sufficient, as they are only intended to be consumed by that application.
Where you see a requirement for different versions of the same application (mobile, tablet, web etc), then moving the Web Api to a separate project makes sense, as each application can then access the same API. This Web Api would contain your data access and business logic layers within it. This allows complete separation of your projects then, and provides maximum reusability, and ensures consistency in data between different versions of your project. Obviously with this set up, your Web Api layer is seperate and can be tested/deployed/scaled separately.
So in summary, you need to consider your requirements and assess the technologies available to you to achieve them. Using the above I hope you understand where Web Api fits in and what it can provide.

ASP.NET Web API and untyped data-collections

We want to expose (through an API) big data collections that are a combination of flat file/binary files and xml files. Currently we do this with WCF Data Services (OData), and tranfer this data using a custom Untyped Data Provider as described in this tutorial (past 4): http://msdn.microsoft.com/en-us/data/gg191846
Performance is bad though and customization is hard, so we are thinking of 'upgrading' to ASP.NET Web API (2). Daniel Roth from the Web API team has given an interesting talk at TechEd2013 on the differences between WCF Data Services and Web API (see it here: http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/DEV-B209) and at 1h06m he mentions briefly that 'Web API doesnt support untyped data yet, but it's coming'. I'm a little confused as to what this means for us. Does this mean that ASP.NET Web API is a no-go for us no matter what, or that we can move to Web API, but will (probably) still need a custom data provider? Any insight would be appreciated!
Looks like this update came at the right time: http://www.asp.net/visual-studio/overview/2013/release-notes
Type-less support
You can now build OData services without needing to define CLR types for your entity types. Instead, your OData controllers can take or return instances of IEdmObject, which are the OData formatters serialize/deserialize.

Android MySQL php+JSON alternative

I have written a simple database driven app in C# which uses a 2 table MySQL database. This is all a learning curve for me (except c#, which I am now comfortable with)
The app is small, has a couple of datagridviews, uses a few sql select/inserts statments to populate the datagridviews and also update records.
I want to port this app to Android. All of the internet sources I can find recommend a middle php sript which accepts http requests in order to fetch the data from MySQL and then return the results back to the android device where it is parsed with JSON etc etc.
This method is a little out of my reach since I dont have php experience, all of my attempts to implement the php layer have failed, speciially the android app was not receiving any data back, I'm assuming I messed up somewhere inside the php file.
Is there an easier (more noobproof) way to interact with the MySQL database from within android which doesnt require the need for php + JSON? Any ideas are appreciated, thank you in advance.
If you are comfortable with C#, why not use ASP.Net MVC for the middle man?
MVC is especially easy to deal with JSON, and you actually only need to create those "controllers" (as models should already be there from your existing app, and JSON don't need the View to display).
You can create a Web Service with C# that handles the data retrieval from the database; no need to go with PHP. Try create one with WCF API (check this question in order to create one). In order to create an Android client that consumes JSON on Android check this link.
If your mobile application have to access a database over the network you should indeed build a web service fronted to the database.
By putting a web access layer on top of the database you can expose the required queries in an abstracted, secure and convenient manner.
Though this sort of web service architecture can be implemented with PHP + JSON other technologies can be used as well. If you feel more comfortable with C# you can use it to build the web service instead. By doing so you may even be able to reuse some of the code from your existing application.
Actually, it would be better to take php in middle of android & mysql, due to the security concern and by the way this is the most easiest & comfortable method. here is link link. I hope you like it.

how web applications communicate each other in struts?

I have two web applications in web application server. i want to get data from one application to another. how do i do in Struts. i know that it is possible by webservices. But, is there anyway that i could get it using struts?.
Use query string to pass data using request parameters.
/action.do?varA=1&var2=3
This'll work for simple cases. For complex requirements/exchange please use Web Services or other integration technologies.