Hosting WCF locally - c#

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

Related

How to host websocket-sharp server on IIS

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.

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

HttpListener not receiving remote requests, even with the firewall down and all prefixes registered

I've written a server using HttpListener that works perfectly well for requests sent from the same computer, but doesn't even receive requests sent from a remote machine. I've tried using (including registering with netsh) the following prefixes: http://*:8080/, http://+:8080/, http://localhost:8080/, and the specific IP address of the host computer followed by port 8080. (I also made sure no other applications were using 8080.) I opened up the appropriate ports in the firewall, and when that didn't work, I turned off the firewall just to see if it was a firewall issue and that also had no affect on the problem. I have no idea what to try next, please help!
Also, the machine running this web service is a Amazon Web Services Microsoft Windows Server 2008 R2 with SQL Server Express and IIS EC2 instance.
If you are using AWS free tier EC2 instance, adding the given public elastic IP as the prefixes will not work for you even after you have the local firewall port and ports in security group opened. The HTTPListener needs to be bind with the public DNS provided by AWS. Then only it will work.
For future users, the solution in more detail was to add an Inbound Custom TCP rule that included port 8080 in the 'Port range:' to a Security Group used by my EC2 instance.
thanks to #shashankaholic for pointing that out

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.

WCF self hosting and IIS

Does WCF self hosting, still uses IIS or some Virtual Server based on IIS.
Eg: After coding a very basic WCF host, it s possible to invoke an endpoint such as
http://localhost:9090/foo.svc
For example: invoking a WCF host via TCP, does that use IIS internally?
I m trying to avoid IIS due to another app i m using, which doenst work with IIS Threads. That s why asking. so i d like to manage my own AppDomain and threadpool rather than IIS.
Any recommendation?
Can i seperate hosting of WCF from IIS?
When you self-host, you are using not a shred of IIS at all. You don't need IIS on that machine - nothing.
WCF self-hosting will require the http.sys driver for its http-based communication - but that's all there is. There is absolutely no trace of IIS needed - none, zip, nada.
Self-hosting WCF also allows you to pick your own service addresses and use whatever suits your needs - there's no virtual directory and no *.svc file to be dealt with.
It depends on the bindings. if you do a BasicHttpBinding, then all the communication will be over HTTP.
As for hosting WCF, there is the test server that comes with Visual Studio that you can use (it runs as a service. It's called WcfSvcHost.exe), but I wouldn't recommend it for production. If you are just testing, then you could just launch the WCF in the Visual Studio debugger and use its address all you want (it will be http://localhost:1234/foo.svc in that case)
If you are looking for a production hosting, you can use WCF as a SOAP endpoint, and here there is a pretty good article over at The Code Project that talks about creating a service for self hosting

Categories