I'm writing a web server app for the first time, and I'm not really sure that I know what I'm doing.
Basically I have some server side C# code and a native iOS app. I need to be able to push updates from the server to the app. The method which we have decided to use is Long Polling, and I can see three ways of doing this:
1) Writing my own web server in C# - not neccesarily tempting as it requires re-inventing the wheel
2) Using WCF - I've seen a few articles about how to implement long polling over WCF, but the tutorials that I've seen all seem to use clients which are implemented in .NET WCF which is not applicable for me as I need to use an iOS app.
3) Something else, possibly using IIS - I don't really know where to begin with this option.
Can anyone recommend a good tutorial, or exemplar project which uses standard HTTP to implement long polling with a C# server? So long as it's using standard HTTP, I'm confident with the iOS side of things.
Obviously if there's an even neater way of doing things then I'm all ears as well.
I would highly recommend that you investigate SignalR which allows you to achieve exactly what you are after. There are many iOS tutorials as well as HTML / JavaScript and of course C#.
One of the benefits of SignalR is that it tries to use the best technology available on the various devices and down-grades until it works. So, will start with Web Sockets for example and fail down to long-polling if nothing better is available.
Related
I am responsible for developing the software for a printer-like device, for which I am using C#/.Net and WPF. We now have the necessity for making this software network-capable, so that the device can be remote-controlled over a local network.
The idea I currently have, is to be implement some way of calling the API-functions of our software over the network. This could be done by a client-side DLL, which sends the commands for the API and receives their responses as well as any events, that the device-software issues.
To this date I have only worked a little with socket-based communication using TCP/IP, where I explicitly sent strings over the network and received them on the other side. I did this completely synchronously. However for the new implementation I will need asynchronous calls to the API to query state, issue events, etc. and it seems like it would require considerable effort to implement this using socket-based communication (am I wrong?). I will have to avoid too much custom implementation, since I am under a time-constraint for the implementation.
In my search I came accross the possibility of using SOAP in ASP.Net, which from this CodeProject post, seems to be what I am looking for and does not seem to be too complicate to implement. However in my Visual Studio 2015 installation I am unable to find the project-type they are using there, which is a "ASP.Net Web Service".
My question is now:
Given my choice of technologies (.Net), would this be the most effective way for achieving, what I have in mind? Is it still possible to do this in Visual Studio 2015?
Update:
As always I found one of the questions afterwards: Here is an explanation of how to create an "ASP.Net Web Service" in Visual Studio 2015, which I have tested to work. Leaves the question, of whether this is the best way to go for what I need.
I think that you would have better luck using web api. Calling a REST based api is a lighter load on the network and is generally easier to set up. It is also easier to call from non-Microsoft based clients and usually requires less coding to get started.
Here is a good tutorial on creating a RESTful web api using .Net Core. If you have a PluralSight subscription, they have a number of tutorials on Web Api. If you don't have a subscription, it is well worth the money.
Web Api and WCF are two completely different frameworks. WCF uses SOAP, which is XML based, meaning that the number of bytes needed to send information is much larger than a RESTful service in Web Api. It is much easier to write and deploy a Web Api application and client than it is to write the equivalent in WCF.
I'm in this project:
A web page that's gonna be used by the front-end company people to query and update data from a SQL DB.
I'm working with visual studio and the code behind (C#) is almost done, so the interactions between SQL and C# are ok.
My original idea was to work with ASP.NET which is familiar to me, but that's not gonna be possible. I have to switch to PHP.
So, today is my first day learning PHP, checking http://php.net/manual/en/index.php and a lot of things seem quite similar to ASP.NET so I guess it won't be that hard.
Anyways, some questions popped up quite fast as I wanted to script something else than a "hello world".
Is there an easy way to get/send C# variables from my class using a php page? I've read soemthing about using XML in order to do so, but still I'm scratching my head, is there another, easier, way to do this?
You have options.
direct integration. PHP can instantiate and use .NET objects . See the DOTNET library in PHP. So if you run PHP on Windows, and you expose your .NET logic according to the requirements of the PHP DOTNET infrastructure, then you can just call .NET classes directly from PHP. Some restrictions: PHP is built to integrate with the .NET 2.0 runtime. You can't build .NET 4.0 objects and connect to them from PHP.
synchronous network protocols. As others have suggested you can expose your C# logic via aREST or web services interface, then invoke those services from PHP using the curl library or file_get_contents(). The C# logic could be, but need not be, publicly exposed. In other words, you could make it accessible only from within the firewall of your app, so that no anonymous public access is possible. on the other hand your architecture may call for access to the same API from 3rd-party or user apps. In that case it needs to be exposed publicly.
in either case, public or private, you will want to use WCF or ASPNET MVC to expose these services implemented in C#.
asynchronous mechanisms. PHP can connect to MSMQ. See Using PHP to Open MSMQ Queues . Of course C# can do likewise. You could use MSMQ as a buffering communication mechanism between the two worlds. To do this you'd need to come up with a data serialization protocol, for the messages you put and get on the queue. JSON or XML would be appropriate choices here.
Database. If you are concerned about employing MSMQ as it is "one more piece of infrastructure to manage" you can also employ a database as a go-between. A shared database can be accessed by both PHP and C# and used as a message queue or communication conduit. PHP inserts messages in a MySQL Table, and the C# app could read and process them, then place reply messages in a different table. This would require some work by you to design the message formats, protocols, indexes, and request/reply correlation mechanism. But it relies on proven, existing technology that you already know how to use.
Finally, there is Phalanger. This lets you compile PHP onto the .NET Framework. This means integration between C# and PHP will be simple. I haven't tried this but it might satisfy your requirements.
Good afternoon,
I am looking to have a web service that deals other web services (and databases) to collect data that is then stored within its own database. This is all quite straight-forward as I can regularly poll these to gather changes.
now communicating with the clients is the problem here. The web service can be created in any language (although C# or Java are the main candidates). But they will need to push data to clients written in Silverlight and Android (and others to be decided).
Polling is of course possible but on mobile devices we don't want constant polling, and besides in as real time as possible comms is important here
If this was totally in C# then I would imagine I could use duplex channels but I need something that is more general in order to push. So the question is what is available to do this? Also it needs to be free in an ideal world.
Seems a simple thing, a way to push from a web service toa client but I suspect it is far from simple (but maybe I can be proved wrong, I hope!)
It seems that there is no platform independent way to do what I want and so the way forward has been decided as the following for now:
Silverlight clients will use a polling mechanism to get the data and Android clients will use XMPP to get the messages.
This does have disadvantages in the polling aspect however there are no readily available free libraries to do it that work with Silverlight but in the future we will move to using XMPP throughout when we have the cash
I've got I admit that I'm probably too dumb to fully learn and understand WCF. :(
On the other hand I had learned and used xmpp pretty well ( using MatriX XMPP library ).
So I wanted to ask, maybe there are some other libraries that help passing data from one computer to another to make life simple?
i.e. a library that would open a port/connection and both listen to incoming commands from other computers, as well as be able to send such commands to other computers that are listening to it.
Thanks!
WCF is not a hard technology... there is a learning curve, but ultimately someone who has taken the time to learn how to do it can easily implement the functionality in a couple of minutes.
i.e. a library that would open a
port/connection and both listen to
incoming commands from other
computers, as well as be able to send
such commands to other computers that
are listening to it.
Not really. Most of WCF involves setting up your app.config files so that they work on both ends. And I doubt there are any libraries that can do that for you.
You simply HAVE to generate and implement a service contract and implement the endpoints/meta data.
MSDN actually has a very decent tutorial. Getting Started Tutorial
Even if you DID find a "helper" you should still take the time to learn the technology so that you are prepared to troubleshoot and fix it when it breaks.
And if:
I've got I admit that I'm probably too
dumb to fully learn and understand
WCF. :(
were true... you wouldn't be a programmer.
My journey to understanding WCF happened right here on Stackoverflow... you can check it out at : Cross Application Communication (C#).
It might help you understand a little bit better.
Two options come to mind.
If you want to use WCF, the check out ECollective from SOA Collective. Uses managed mode Discovery to create a config-free WCF client, abstracting all of the things that makes WCF hard like bindings and behaviors.
If you want to use something other than WCF, check out NServiceBus.
Try the Idesign Website ... they have a WCF library that you can download and use in your projects.
Is there any way to have apache "pass" the request it takes to a c# "application" to handle, allowing it to return specific content. I want to handle an intense amount of asynchronous calls to apache via javascript and have these calls routed through c# (much the way asp.net does). Has anyone successfully done this before? Any idea where to start looking?
Update:
Some more information. I want to be able to handle thousands of concurrent asynchronous requests as fast as can possibly occur writing the interpreting agent in some kind of threaded c# application. I could be wrong, but I dont think that iis with asp.net is tailored for this sort of thing (a proof of concept would be great).
I feel that going with something like apache would be better suited. If that means going from something else to c# first is fine I guess, but I would like to be more direct.
Apache actually supports running C# libraries using mod mono. Also, you could use CURL to send a web request to C# running on IIS. Another way would be to open a server socket directly in C#, and have apache (via php, python, or some other scripting language) connect to you C# application to handle the request. I think you need to be more specific about what exactly you are trying to accomplish.
with apache2, you could run mod_aspdotnet
or if it suits you, run some urls in proxy mode (pass them to another asp.net server), using mod_proxy
or Kibbee's excellent solution