Sign in to follow this  

C# Server with HTTPS

This topic is 4101 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I' currently searching for tutorial to developpe a C# server communicating with HTTPS. I'v search a lot on the web for such thing, but always found website that explain that with ASP.Net. Sadly I think that ASP.Net doens't give me the flexibility that I need. So if anyone got any nice tutorial (Client/Server side, mostly server) It would be really nice. Thank.

Share this post


Link to post
Share on other sites
I am not trying to discourage you here but: What are you trying to accomplish? If you do not know what HTTPS/SSL is why are you building this? If you are looking for safe communication without installing IIS (or alike) perhaps Windows Communication Foundation might be an answer. Another option (if HTTP is not required but just safe communication) .NET 2.0 remoting might just be what the doctor ordered...

Share this post


Link to post
Share on other sites
Quote:
Original post by ernow
perhaps Windows Communication Foundation might be an answer. Another option (if HTTP is not required but just safe communication) .NET 2.0 remoting might just be what the doctor ordered...


I'm not going to say that these are bad options for general use, but I hate these kind of suggestions for a beginner who probably doesn't even understand the basics of encryption. All you really need for secure communications are sockets and an encryption routine. An ultra-high-level API is a dangerous crutch if you don't understand what it's doing behind the scenes.

Share this post


Link to post
Share on other sites
Quote:
Original post by ernow
I am not trying to discourage you here but: What are you trying to accomplish? If you do not know what HTTPS/SSL is why are you building this? If you are looking for safe communication without installing IIS (or alike) perhaps Windows Communication Foundation might be an answer. Another option (if HTTP is not required but just safe communication) .NET 2.0 remoting might just be what the doctor ordered...


I have a project to make for a real compagny. The server and the client will be at different place. I have some basic experience with client/server communication but NOTHING about security. If you guys have tutorial along with what you propose, I't would be perfect. thank

Share this post


Link to post
Share on other sites
Quote:
Original post by paulecoyote
Poke around here for WSE http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx



The problem with WSE is he is going to need to run ASP.NET or another webserver to implement what he wants. It sounds like he wants to implement his server lightweight in code.

Ironically, its not very hard. The gist of it is, first you need to create your TCP server. To do this you will inheirt from System.Net.Sockets.TcpListener(). This will provide you will your TCP server without needed to use ASP or any other 3rd party software.

Once you have your server in place, you are going to want to use System.Net.Security.SslStream for all of your https traffic. This part is a bit more complicated, as you need to setup your certificates, etc...

The following example from Microsoft though should show you everything you need to know. Of course, you will have to make a client after, but that parts alot easier.

Microsoft article with sample source here

EDIT: Oops, no auto linking...

Share this post


Link to post
Share on other sites
Dear Serapth,

I'm really interested about your solution. It doesn't look that hard at first look. I still have some experience in communication between a server and a client over the internet, (C++ and Java) But we didn't see the security part yet in any of my class.

Big thank to everyone. :)

Edit : Just a last question, as I can read, It's not avalable on the framework 1.1? Because I only own MS2003, and no money to buy 2005 :(
(I'll get the Express version if signup still avalable, but I won't be able to sell it heh)

Share this post


Link to post
Share on other sites
Quote:
Original post by Serapth
Quote:
Original post by paulecoyote
Poke around here for WSE http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx



The problem with WSE is he is going to need to run ASP.NET or another webserver to implement what he wants.


Actually it's independant from transport, you can just TCP. WSE 2 is .Net 1.1.

If you download the WSE Quickstarts you'll find an example called "TCPStockService" which illustrates this


/*=====================================================================
File: StockService.cs

Summary: This is a sample which allows the user to send a message
to a Web service. This sample illustrates using the same client proxy
to call either an ASP.NET Web Service via HTTP hosted in IIS or
an Web Service hosted by a console app via TCP.

To run this sample first run the TCPStockService Console App built here
\Samples\CS\QuickStart\Basic\TCPStockService\TCPStockService\bin\Debug
then run the client, assuming that you have already created the vdir
for the IIS hosted service by running CreateSampleVdir.bat

---------------------------------------------------------------------
This file is part of the Web Services Enhancements 3.0 for Microsoft .NET Samples.

Copyright (C) Microsoft Corporation. All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation. See these other
materials for detailed information regarding Microsoft code samples.

This sample is designed to demonstrate WSE features and is not intended
for production use. Code and policy for a production application must be
developed to meet the specific data and security requirements of the
application.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
=====================================================================*/


using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

using Microsoft.Web.Services3.QuickStart;

[WebService(Namespace = "http://stockservice.contoso.com/wse/samples/2005/10")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class StockService : System.Web.Services.WebService
{
public StockService()
{
}

[WebMethod]
[SoapDocumentMethod(ResponseElementName = "StockQuotes")]
[return: XmlElement("StockQuote")]
public StockQuote[] StockQuoteRequest([XmlArray(IsNullable = true), XmlArrayItem("Symbol", IsNullable = false)] string[] symbols)
{
ArrayList list = new ArrayList();
foreach (String symbol in symbols)
{
StockQuote quote = new StockQuote();
quote.Symbol = symbol;
if (symbol == "FABRIKAM")
{
quote.Name = "Fabrikam, Inc.";
quote.Last = 120.00;
quote.PreviousChange = 5.5;
}
else
{
quote.Name = "Contoso Corp.";
quote.Last = 50.07;
quote.PreviousChange = 1.15;
}
list.Add(quote);
}
return (StockQuote[])list.ToArray(typeof(StockQuote));
}
}



Share this post


Link to post
Share on other sites
Ok, I'v tried to create my server in C# with your documentation Serapth. I have only one problem remaining, How on earth do i create a certificate, and where do i configure this with my server. I have No idea how this work. I searched on the internet but there is so many different certificat under different server that i don't know what to chose. :(

Share this post


Link to post
Share on other sites
Ok, I'v tried to create my server in C# with your documentation Serapth. I have only one problem remaining, How on earth do i create a certificate, and where do i configure this with my server. I have No idea how this work. I searched on the internet but there is so many different certificat under different server that i don't know what to chose. :(

Share this post


Link to post
Share on other sites
Quote:
Original post by deathwearer
Ok, I'v tried to create my server in C# with your documentation Serapth. I have only one problem remaining, How on earth do i create a certificate, and where do i configure this with my server. I have No idea how this work. I searched on the internet but there is so many different certificat under different server that i don't know what to chose. :(


Sorry, cant help much. The only time I needed to do this stuff, the place I was at had its own cert server, so it was a relatively trivial task to get one.

Share this post


Link to post
Share on other sites

This topic is 4101 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this