I am fairly new to hosting web applications and web services. Though I was successful in hosting a web application, I am running into road block after road block when trying to host a WCF service with net.tcp binding.
My scenario is as follows, I have a hosted web application that needs to communicate with a hosted WCF service with net.tcp binding through IIS 7.5. As stated the web application is hosted fine and I can browse the web site. However, the web application makes services calls to the WCF service and I am getting the 'TCP error code 10061' message which I believe is due to my hosted WCF service not running. I think this is not running because I attempt to 'telnet localhost 808' to see if the WCF service is running and it is not. I've run through numerous online guides and I still have had no luck. I believe I may be doing something fundamentally wrong with me being a noob and all. I am able to host the service through VS2010 and run the web application and it works fine so I believe my bindings are correct. I've also enabled tcp protocols on both websites in IIS Manager.
So I guess my real question is what are the IIS Manager steps needed to host a WCF service with net.tcp binding? It appears to me that it is not possible to host a net.tcp service through IIS Manager by simply creating a website because IIS Manager wants to bind to an http port.
Here are some things to check:
Ensure the Net.Tcp Listener Adapter windows service is running
Ensure netTcp is listed as an enabled protocol for your website (In IIS Manager, go to Advanced settings for your site)
Ensure netTcp is listed as an enabled protocol for application (directory) that is hosting your services (In IIS Manager, go to the directory hosting your services and select Advanced Settings)
Ensure your IIS site has a binding for net.tcp, with the correct port number listed.
EDIT:
See the following MSDN page for enabling/using non-HTTP bindings in .Net 4 + IIS 7/7.5:
Configuring the Windows Process Activation Service for Use with Windows Communication Foundation
And I discovered that for me it didn't work to use localhost... You should use 127.0.0.1 or the name of your computer.
Related
I have developed a REST service using WCF and hosted it in a windows service and that works fine on a machine which has IIS installed, but not on a machine which does not have IIS. On the machine which has no IIS, if I browse http://localhost, it says "cannot display webpage". so do I need to install IIS to get this working, even though the WCF service is not hosted in it?
No, IIS is not required. The reason you can not brows to localhost
is because that is going to port 80 by default, and because you have no IIS, there is nothing there to direct to to a webpage. (Not unless you had a windows service to take in the http request on port 80 and send back an HTML page, but that would be weird.)
But in short, you do NOT need IIS to run your windows services.
If I run a WCF application which exposes a service in visual studio, is it possible to consume the service from an asp.net application running on another computer? How can I determine the address of the WSDL published by the WCF service in order to add a reference to it in the ASP.NET application?
If your service is an ASP.NET application and you are hosting it with the built-in development server, refer to Kalus's answer. However, if you have IIS installed locally, you can reconfigure your project settings so that the application is hosted by IIS for debugging instead of the built-in development server.
If you are writing a standalone WinForms or Console application, then the responsibility will be on you to select an endpoint and binding, whereas with an ASP.NET application, those parameters will come from IIS or the Dev server (the protocol will always be HTTP/HTTPS, and the port number will be set by IIS or randomly generated by the Dev server). So in a standalone application, you will have to configure which binding (basicHttp, wsHttp, netTcp, etc.) and an appropriate hosting endpoint (http://hostname/MyService or net.tcp://hostname:port/MyService). But yes, if the service is hosted by a standalone application, it will be accessible from other computers.
Refer to this overview here: http://msdn.microsoft.com/en-us/library/ms731758.aspx
According to #Kent Boogart's comment below, the asp.net development server can only be used for local requests. So you will need to configure your web service to run in IIS if you want to call it from another machine.
How to host WCF services locally instead of http binding.. I mean the services should be hosted within the .NET environment and not by using http or netTCP.. Could you please help me with the configuration for the same?
What are you trying to achieve here that can't be performed by using http or tcp settings for the local machine for both ends of the WCF contract? WCF isn't just between machines, you can also set it to communicate between different processes on the same machine.
I think you are confusing between hosting a WCF service and a WCF binding. A WCF service can be hosted in many different applications such as standalone executables, windows services, a web server such as IIS, ...
Once you've found an appropriate host for the service you have to decide what binding to use. A binding is used to specify the transport, encoding, and protocol details required for clients and services to communicate with each other.
Note that choosing a host could further limit the choice of bindings available. For example if you decide to host your service in IIS you could only use HTTP/S as transport and NetTcp is not available (in IIS7 it is available through WAS).
How to confgiure NetNamedPipeBinding.
How to: Host a WCF Service in a Managed Windows Service.
Is it true that a WCF either runs as a console application that you have to manually start OR under a more traditional IIS application (like a website or webservice)
you can start a WCF host process in a:
Windows Forms App
Console App
Windows Service
IIS 6 (Only HTTP hosting)
IIS 7 - WAS (All bindings supported)
Each of them has advantage or disadvantages. This page gives great information about hosting options: http://msdn.microsoft.com/en-us/library/bb332338.aspx.
EDIT: No, that is not quite true.
Those are two hosting options for WCF. There are others.
orig answer:
you can actually execute a wcf service everywhere, where you can execute managed code.
i've seen wcf services running inside sql server, wpf apps, windows services and even one running on a linux box on mono.
There is a class ServiceHost defined in WCF that allows you to host a service in any application like so:
using (ServiceHost host = new ServiceHost(typeof(MyService))
{
host.Open();
WaitForClose();
host.Close();
}
IIS running in Windows XP SP2+, Vista, 2003 or 2008 can host WCF services.
Yes, that's correct... you can also host them as a Windows Service
Part of the objective of WCF is to free you up from limitations on where the service is running. You can also use Windows Activation Service (WAS) for Vista and Windows Server 2008.
I have a WCF service that needs to run as a service in IIS 7.
The problem is that in order for it to start I need to manually invoke it through the browser e.g. http://site/myservice.svc.
Is there a way to have IIS call out and start the service host / wcf service when the application pool is restarted?
My preference would be to avoid a windows service and go with IIS / WAS
I have created a WCF service with NetMsmqBinding, and hosted it in IIS7 using Windows Activation Service (WAS).
Current (works perfectly):
Hosted in IIS at: http://localhost/MyService/MyService.svc
With the service endpoint address: http://localhost/private/MyService/MyService.svc
And the corresponding queue: .\private$\MyService/MyService.svc
Desired (does nothing, not even an error message):
Hosted in IIS at: http://localhost/MyService.svc
With the service endpoint address: http://localhost/private/MyService.svc
And the corresponding queue: .\private$\MyService.svc
Everything works perfectly when I use the MyService IIS application. But the same setup (code, IIS security, queue security, etc.) does nothing when I try to use the root "/" app instead of the "MyService" app to host the service. I don't get any errors in the Event Log. The incoming messages just sit in the queue.
Is hosting a WAS-activated service supported in in the root application of an IIS7 site?
I found a bug whereby hosting WCF services in the root (spent a lot of time on the phone with MSFT Support), thus host them in an application.
For example, I have a netMsmqBinding service hosted in IIS7, it is configured for WAS and it is hosted in the default site as:
http://mymachine/msmqtest/service.svc
The queue name for MSMQ needs to be called:
"msmqtest/service.svc"
And the endpoint in the config needs to be:
net.msmq://mymachine/private/msmqtest/service.svc
Also, make sure you are using the machine name in the config, NOT a host header name or something. MSMQ works from computer to computer, very important.
Hosting of WAS Activated Services do work rooted. I'm not 100% sure about the netMsmqBinding. the end point would need to be http://localhost/service.svc not /private though.