This might seem like an odd question and is probably very specific to our current requirements but I couldn't find anything through Google, so I thought I would give this a shot.
I am working in ASP.NET C# MVC4, and with a backend that is a legacy database system. We have two MVC projects; one for the API which interacts with the database and one for the front end which returns Views etc and interacts with the API. From the API, we are able to run subroutines that exist on the backend database server.
I am making an HTTP request from the front end to the API which contains JSON-encoded data. The API will use this to run a subroutine on the backend (the subroutine will save the data on the server and send out emails).
My question is this: What HTTP method should I use in this case?
For right now, I chose a POST request, and since this isn't an idempotent action, I think it is the best choice but it isn't really a CREATE operation, so I wanted to ask if anyone had any different advice.
Related
I need to be able to get the results of database queries run on my Webpage to a SQL Server database regarding user information sent from my game in Unity. I'm a gameplay programmer with significant experience in C#, but I'm at a loss trying to figure out how to make this happen.
The bare minimum I need to figure out is how to send a user/password combination to my web page, check the database for the username, and store it if it does not exist. Finally, sending back a Success or Failure depending on whether the user/password combination already existed.
In Unity I have at my disposal two classes for sending HTTP requests.
1.) https://docs.unity3d.com/ScriptReference/WWW.html
2.) https://docs.unity3d.com/ScriptReference/WWWForm.html
I have basic (very basic) understanding of how web technology works, but the finer details required to make this happen are beyond my current knowledge.
My website is hosted on Azure running ASP.Net MVC. Any help at all or pointers in the right direction would be greatly appreciated.
I have so far been able to get some results back using WWW, but they are meaningless to me and I wouldn't know how to tell if the results of a query were even working (based on the responses). I can of course directly check the database for success, but I need to be able get the results in Unity.
My specific goal:
Send two strings (Username, Password) to an ASP.Net MVC Web app. Have the web app add the two strings to a database if the username is not already in the database. Finally, I need to be able to send the result as a string (Success/Failure) to Unity somehow. This is the part I am most clueless on.
I have an MVC 5 project with an OData V4 web service for the backend, and I'm starting to run into some confusion when it comes to retrieving data (not views).
I'm not sure whether I should be making my web service calls through ajax or through an MVC controller action with an HTTP client. I know you typically want some additional separation in the latter case in the sense that the controller action probably shouldn't be directly calling the web service with an HTTP client, but regardless. I should also reiterate that my question has nothing to do with Views/PartialViews; I always call a controller action to return those.
Is it only advantageous to go through a controller action when you need to perform additional work on the data being returned?
If I'm simply retrieving a list of objects from the web service, is there any point in taking that extra step by calling a controller action?
Sorry if this has been answered before. I found some vaguely similar questions but nothing too concrete.
Thanks.
If the web service resides in a domain other than your web app domain, you probably will run into same origin policy issue when trying to make ajax call from your pages. Basically this is not a problem, but a security feature where a web browser permits scripts contained in web page A to access data in a web page B, but only if both web pages have the same origin. An origin is defined as a combination of URI scheme, hostname, and port number.
If you have this problem, you can try to access the web service from your server code(controllers/services). This also allows you to parse the response coming back and converting to another format which your view really want. If you are accessing data which won't be changed very often, you may cache it also using MemoryCache or other dot net caching solutions. This will save you some network calls and improve your page load time.
I have coded a C# MVC5 Internet application and I have a Web API 2 web service that returns JSON data. I am retrieving this JSON data in an android application.
How can I add a feature to the web service such that only my android application can retrieve the JSON data? I am wanting to do this so that other web users cannot hammer the url and the web service will not send my data to unwanted applications and/or users.
Is this possible? If so, how should I do this?
Thanks in advance.
You have various ways to achieve this in fact.
For example, you can store a key in your android application and use send this key together with the request to your WebAPI. Your webAPI will than check if they key is valid and if it is, it will return the JSon.
However, there's no way to ensure that nobody else can request and get your data. For example by reverse engineering your android application and extracting the key, or by monitoring the network traffic and find the key in there.
You need to understand that there isn't anthing that guarantuees you 100% security.
See it as the following:
You have an open door right now, you can close it little by little, but closing and locking down is not possible. There will always be gap. A house also can't by made burglar proof, but you can make it very hard for a buglar to enter.
Go to this link Web Api. I have used the individual authentication for my web api. When you will register the user the response you will get is access token and use that access token as Authentication header in your ajax call if you are using Jquery ajax to call your Web Api. Refer this The OAuth 2.0 Authorization Framework. Hope this help you.
Are you looking for something like this?
http://httpd.apache.org/docs/2.2/howto/access.html
If you have other web server, there should be appropriate means to support such.
Here's an API server which can give me real time news: every minute there will be something new to retrieve. There's also my web page, with a Javascript that will ask the API to get some news once every minute.
And this is not fine... unless my web page is made for a single user and will be open only on one machine at a time (which is not the case of the internet). the API, infact, restricts the number of call I can do per minute: let's suppose the API will ban me if I do more than 1 call per minute. If 100 users will load my web page, the API will receive 100 calls per minute (!!!).
Since the flow is my web page >> calls >> the API I think there is no solution without inserting another node which lazy loads from the api server.
my web page >> calls >> my server >> calls every minute >> the API
Since the instances of my web page may be many while my server is just one I think this is the solution.
However, I have no idea if:
a) is this the correct solution? Or could I somehow get my web page to behave correctly without the need of an intermediary server?
b) how can I implement this in ASP.NET MVC4? Is there any support for server side timers?
c) even if I can get IIS to retrieve the data every minute, should I then store it in a database to serve it to my web page?
d) the api server I'm talking about is The Times Newswire API. If anyone ever used a similar API, did you really created a domain model, a database table, a service and a routine just to retrieve data from it or did you just writed some javascript code in my web page? What then if you have milions of users?
You can use SignalR for this purpose, This is a push service which works by using sockets and therefore can be configured to send out one message to 1,000,000 listeners (or more obviously).
I've used this to great effect when creating a little prototype game last year and found it to be very reliable. You can use NuGet to grab the package in vs2010 and vs2012.
see Asp.net SignalR, see examples or simply google SignalR and you'll find a host of examples.
the API will ban me if I do more than 1 call per minute
Then you need a solution that calls the API for you every minute and stores it on your server. There's tons of ways of doing this, depending on many requirements. You can even go as far as writing a static HTML file which you then show the client.
You should call the API from your serverside. Fetch it one time every minute to your database. Then serve it to the users from your database via in example a restful service. ASP.NET MVC 4 can make all of this.
Also yes it do have a timer. You can check out Timer class.
You don't have to struggle with API restricts with this solution.
A) The best solution is probably to use your web server as an intermediate to the API
B) There are a lot of possibilities to choose from. The easiest would be starting a new thread when the web application starts (i.e in the Global.asax OnApplicationStarted event), and have that thread poll the external API and store the result for your clients to fetch. Another options, if you want full control of the lifecycle of this background procces, would be to create a windows service and host for instance a WebAPI in it that you clients can connect to.
Of course, these are just suggestions.
C) Depends on whether you want your clients to be able to access the latest fetch data, even if the background process has failed and the data is old. Otherwise, you can just store it in a static field somewhere. As long as the application isn't terminated the static field persists its value.
The ERP application we use has webservices but not with the functionalities we want.
So we would like to build an in-between webservice which forwards the request to ERP. And sends the result back without the requester, to even noticing, the difference. We don't know how the wsdl will look. It can be a list of customers, or one item. thats not important.
Is this something you have done/seen before? I have looked for examples everywhere I can think of. The code im trying to do it now with, just reacts as a webrequests.
I would like to show the visitor an adjusted wsdl from the ERP webservice and it has to be modified a little bit to accept a simple login en from then on forward the requests.
I was thinking the visitor logs in first and after a check receives a session id. This session id needs to be added always into an extra header value with the original webservice. These I will translate to the ERP webservice.
Hope someone has seen such an implementation and give me some hints/links.
The webservice can run in ASP but I prefer it to be a simple service in Windows.
I found this:
http://www.java2s.com/Code/CSharp/Network/ImplementsamultithreadedWebproxyserver.htm
Don't know if it will work in production but it looks to be passing it all thru..
Please comment if you see issues with this?!