How to host websocket-sharp server on IIS - c#

I have a hostname like dev.websocketserver.com.
Now I want to host my websocket-server on this hostname in IIS, so that my socket address becomes
ws://dev.websocketserver.com/Echo
What should I create WCF service, windows service? Socket will listen on port that is not already in use. So if I host my WCF service under host dev.websocketserver.com and in Global.asax create a server then it will not get bound with Port 80.
Can anyone tell me what should be the basic architecture for hosting websocket-server over IIS?

As far as I know, you can't.
websocket-sharp needs to run in its own port, so you cannot have both IIS and it in the same port.
You can run both in the same host and have ws://dev.websocketserver.com:8000 for example.
IIS 8 and further supports WebSockets, so you can use the built in WebSockets in ASP.NET rather than websocket-sharp.

Related

Right way to specify base address in WCF service with net.tcp

Suppose I've one WCF service hosted in a Windows service running on a machine on LAN. I want to make this service to be consumed by applications running on other machines on same LAN. Further assume I've hosted WCF service in a Windows service using TCP. So the app config file will have the base address mentioned something like this:
<add baseAddress="net.tcp://localhost:8523/Service1" />
My question is will this service be accessed by clients over LAN though I've mentioned localhost? What is the right way to mention base address so that service could be consumed by clients on LAN? Is any arbitrary address is valid? If localhost is valid, which port shall I mention?
you need to specify the actual ip. i think localhost is just for the current machine. localhost is an alias for the default address 127.0.0.1

Hosting WCF locally

Can I host a WCF Service using netTcpBinding which is accessible (please note i am asking about ACCESSIBLE means browsable) in the same machine (localhost) and not outside the localhost... not even intranet.
I should think so, as long as the port it's running on is not externally accessible (e.g. blocked by a firewall).
This can also be done at hosting level (in IIS):
open IIS manager
select WCF service application folder
open "IP Address and Domain Restrictions"
if it's not there, you have to add the "ip and domain restrictions" role to the server
in "ip address and domain restrictions" enter an allow entry for 127.0.0.1
then under "edit feature settings" set "access for unspecified" to Denied
Doesn't matter how the service is setup, IIS won't allow access outside 127.0.0.1
EDIT: This feature is not available on IIS 5.1 (Windows XP). You're going to need a firewall, or check out IIS Express.
You can host WCF services by using IIS (only 7.0 or higher for net.tcp) or as windows service.
For IIS you should create site or web application and add binding with port for net.tcp protocol.
There is no difference between hosting on the localhost and on a remote computer.
In general, it is better to use NetNamedPipeBinding for local connection
As suggested by, Henk Holterman
NetNamedPipeBinding is the best approach when we host the service inside a loaalhost and the service requires just intra process communication like communication with another WCF in the same machine or say a .Net client present in the same machine...
Again, netNamedPipeBinding makes the communication faster because
1) Serialization takes place in binary format
2) unlike netTcpBinding where we communicate through a Port, netNamedPipebinding uses named pipes to communicate between process.
Thanks.
Suraj

How to allow remote connections to my .net application?

I'm writing an application with both a desktop and a mobile app component. The desktop app is being written in c#, and I'd like to be able to open it up to act as a server for the mobile app (similar to what AirVideo does). How can I accomplish this without requiring the user to configure their firewall and/or router?
Ideally, I want to self host a restful wcf service in the desktop app. I've tried this already, but the automatic configuration of the firewall doesn't allow remote connections to the wcf service, since it appears to be hosted by the system process. Is there a workaround for this behavior?
Edit: I've solved the router problem as best I can through the use of the NATUPnP COM library (http://pietschsoft.com/post/2009/02/05/NET-Framework-Communicate-through-NAT-Router-via-UPnP.aspx). I still need to know how to allow remote connections through the firewall to a self-hosted WCF service without any manual configuration of the firewall (I'm okay with the user prompt to allow connections once the app is launched).
Set a specific port in your router that is designated to route to your server address,
So if your router real ip is a.b.c.d, you should set up that all communication to a.b.c.d:port# is being routed to your server local address. (a.b.c.d:port# --> serverIP)
The settings for this can be achieved from your router configuration.
In a situation where you cannot tinker with the router setting/firewall settings:
This means you cannot use ports to listen to incoming connections and can only use outgoing connections. to overcome that you will have to use a 3rd server with real IP-Address which will function as a listener for both sides. Typical scenario can be described as follows:
Client Side - A (Desktop)
Client Side - B (Smartphone)
Server Side - S (Communications Server)
S --> Open port for listening to incoming connections.
A --> Connect to S every x seconds to check if requests to do something are waiting.
B --> Connect to S. (issues a waiting request for A)
That way S is served as a proxy to glue both sides' communications.

Host TCP Chat Server in IIS

Im looking at this basic chat server/client tutorial using TcpClient in .NET. Now I would like this put the chat server online on my web hosting provider. Is that possible? Can I host this server in IIS somehow? I could probably just start it in Application_Start but I dont think Im allowed to open a connection on any port just like that. What options do I have? I have made a chat app using WCF and net.tcp before but my hosting provider has not activated net.tcp on their IIS-server. So now Im looking at using a TcpClient instead...
I'd avoid attempting to use TCP in shared hosting scenarios. Why not use a HTTP WCF service instead? Most hosts lock down most ports except standard 80/443 and a few others. I can't see that they would allow you to open an arbitrary tcp port from their server, it could be a big security risk.
I would not host a chat in IIS since you are limit to the application pool lifetime. Look after a hosting company that provides virtual servers instead.

"port forwarding": redirect calls to webservice at port 8081 to port 80

a colleague of mine wrote a webservice that runs on port 8081 of our Windows 2008 Server.
He uses the class ServiceHost, afaik this means its a standalone host (no IIS or ASP involvement). Note: I'm new into WCF ;)
Now there are some issues with clients behind a firewall blocking the requests to remote port 8081 of our server (where the webservice runs). The easiest solution would be: run the webservice host at port 80 ... But: there is also a Apache 2.2 webserver running on the Windows Server, hosting some websites. By default it runs on port 80.
My solution after some researching: use a virtual host to route requests to a virtual host (lets say http://webservice.[hostname]:80) to the webservice host (http://[hostname]:8081).
Is this a good idea? Can Apache handle forwards to standalone webservice hosts?
It would be nice if someone could lead me on to the right track :)
Best regards,
Niels
If your Apache server is your forward facing server and you want the requests to be forwarded to your internal service/IIS you should look at mod_proxy and configuring a reverse proxy.
The easiest solution would be to get a different IP address to run the WCF host on. Then, you could have both listening on the same port but different IP addresses.

Categories