0

I know I may receive red arrows for asking a broad question but I've searched a lot and I'm still stuck.

I have built my application in C#.Net, it is a desktop application with its own graphical interface. At some point the application fires up a dialog, connects to a server, sends some data and receives a file in the same dialog. The user clicks on a button and saves the file on his local computer.

Now my question is what is the best approach to communicate with the server. Windows or Linux doesn't matter. I just need the easiest way to achieve this. Even some keywords to start with a valuable to me.

Vahid
  • 5,144
  • 13
  • 70
  • 146
  • How do you connect now to the server? What do you use? Is there anything specific you don't like in the approach or you're just interested in best practices? – Michael May 03 '15 at 19:44
  • 1
    Well, it depends based on the server endpoint - what is on the server side? If it is a web server streaming file over `http` than definitely the simplest is to use `WebClient` class. – Dusan May 03 '15 at 19:45
  • 1
    Are you just making desktop client, or you need to make a server side also? – Dusan May 03 '15 at 19:53
  • It's unclear if you're in control of both the service and the client, or only the client. If you're only creating the client, the owner of the service should be able to tell you how you can connect to it, and at what location. In this case, you need to include detail around how you're expected to and any problems you're having. If you're responsible for both the client and server portions, and are simply asking where to start your question is likely too broad for SO. – Preston Guillot May 03 '15 at 20:00
  • I think that this question is related to: http://stackoverflow.com/questions/30016708/is-the-security-of-this-net-application-flawed Steps 4, 5 and 6. I would go for `asp.net` server side and `WebClient` on the cliend side over `https`. It is very simple approach. – Dusan May 03 '15 at 20:08
  • @PrestonGuillot Yes I was just asking where to start. I'm the owner of both. The server side only needs to create a file based on the data it gets from the client and send him the output via the same connection. – Vahid May 03 '15 at 20:10
  • @Dusan I'm making both. But I'm not sure what is the best way to connect to the server to send and receive data. – Vahid May 03 '15 at 20:16
  • @Dusan I cannot go for web client on client side, because the application needs its own interface. – Vahid May 03 '15 at 20:18
  • 1
    The WebClient is not a browser or anything like that, nothing like that. It is just a class that can make requests and download data over http. – Dusan May 03 '15 at 20:24

2 Answers2

1

There is a lot of examples on how to generate and stream content from the asp.net - for example the csv file:

var HowMany = Convert.ToInt32(Request.Params["HowMany"])
Response.Clear();
Response.ContentType = "text/csv";
Response.AddHeader("content-disposition", "attachment;filename=test.csv");
for (int i = 0; i < HowMany; i++)
{
    Response.Write(i + "\r\n");
}
Response.End();

On the client side, use WebClient to download content:

WebClient myWebClient = new WebClient();
myWebClient.DownloadFile("http://myserver.com/generate.aspx?HowMany=100", @"c:\test.csv");

A couple of other examples:

https://stackoverflow.com/a/848774/461810

http://www.dotnetperls.com/webclient

https://stackoverflow.com/a/1883697/461810

https://msdn.microsoft.com/en-us/library/9w7b4fz7%28v=vs.110%29.aspx

Community
  • 1
  • 1
Dusan
  • 5,000
  • 6
  • 41
  • 58
  • 1
    Thanks Dusan, so the `webclient` class will download the file from the interfsce of my application not a browser right? – Vahid May 03 '15 at 20:25
  • 1
    Thanks this is what I was looking for a start. Any extra useful tutorials is much appreciated. – Vahid May 03 '15 at 20:26
0

There are many protocols(http , tcp , netpipe , ) that you can use for your purpose.

For Example : if you are communicating with .net application with .net server services then you can use net pipe protocol to get data more faster and reliable and so on.

John Saunders
  • 160,644
  • 26
  • 247
  • 397