We have created a service host console application that needs users key stroke to close it and the code snippet is as follows:
........
host.Open();
Console.WriteLine($"The service is ready {host.Description.Endpoints?.FirstOrDefault()?.Address.Uri.ToString()}");
Console.WriteLine("Press <ENTER> to terminate service.");
Console.WriteLine();
Console.ReadLine();
Console.WriteLine("<ENTER> pressed, about to Shutdown Service Host ...");
host.Close();
Console.WriteLine("Service Host is closed");
.......
I would like to remove user intervention to close the host and keep it opened. Will commenting host.Close() line confirm that it is still opened ?
-------------------------------UPDATE --------------------------------------
My previous post probably was not clear enough. I am looking forward to a machine to machine interaction to start and stop WCF Service Host instead of the human to machine interaction. Our current solution is based on the following:
How to: Host a WCF service in a managed app
The problem we are facing is that the .exe based on the above solution shuts down right after is started the channel at a certain end-point address. It is obvious that the ENTER is pressed somehow
Is the following can be probable solution to what we are facing ?
How to: Host a WCF Service in a Managed Windows Service
You just need to remove host.Close(). The host.Close() method will make the communication object transition from its current state to the closed state. For more information about ServiceHost Class, you can refer to this link.
UPDATE:
As long as host.Close() is not run, the WCF service will remain open under normal circumstances. If the WCF service is hosted in a Windows Service, we can start and close the WCF service by running the Windows service or stopping the Windows service.
WCF can also be hosted in IIS. The WCF service hosted in IIS is like a Web application. As long as the site is in the Start state, the WCF service will always run.
For more information about "Host a WCF Service in IIS", you can refer to this link.
Related
I am trying to create wcf service and want to host on windows service.and install that service on windows.
so what I did I add wcf service library then built and run. after that its does successfully.
but when I create anther WCF appilcation so shows me this error= System.ServiceModel.AddressAlreadyInUseException.
SO how can I solve this issues please help to resolve this issue.
I install InstallUtil.exe but process not start on windows.
I want to host my WCF service on window and consume that service on my client application
First, I suggest you use WCF service application Template to create WCF service.
The error mainly indicates that the http address is already in use, we could change the port number and try it again.
At last, we had better use administrator account to install/run the windows service since the system layer driver (http.sys) manages the machine port. We could also use the below command to reverse the URL for the account runs the service.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-http-and-https
https://learn.microsoft.com/en-us/windows/desktop/http/add-urlacl
Feel free to let me know if there is anything I can help with.
We created WCF Service and hosted in IIS in a specific machine.
WCF Client is hosted in some other machine which is there in the same LAN.
We were able invoke it. Suddently it started giving error. It is throwing some Timeout exception.
Please tell me the possible scenarios to get this kind of errors. If the WCF Client and WCF Service both are in the same machine, then it is not throwing any error.
Can you ping the service from the machine where the client is set-up?
Are there any firewalls causing this problem? But you said you were originally able to invoke it? are there any event logs to draw from?
You can try set up WCF loging
I am new to wcf programming and I have been working on a small project and am having problems with net.tcp port sharing. I am using .net framework 4 and iis 7.
I have two wcf services (serviceA and serviceB) being hosted on our server in separate websites on IIS. Each website has its own .svc file, web.config and bin. If I have each of these services on different net.tcp ports then there is no problem and I can add the service reference to each of them from visual studio on my pc. The services run fine.
However we will soon be starting a project with many more services and we wish to avoid having to open a tcp port for each one so I have been trying to get serviceA and serviceB to port share. If I set them up on the same port then I can access the first service I add but when when I try to access the second service added to the same port i get the following error:
Metadata contains a reference that cannot be resolved:
'net.tcp://myserver/serviceB.svc'. The socket connection was aborted. This
could be caused by an error processing your message or a receive
timeout being exceeded by the remote host, or an underlying network
resource issue. Local socket timeout was **. An
existing connection was forcibly closed by the remote host If the
service is defined in the current solution, try building the solution
and adding the service reference again.
I can not work out what is going wrong. I have done a lot of searching on the subject and I have made sure that the following services are running:
Windows Process Activation Service
Net.Tcp Port Sharing Service
Net.Tcp Listener Adaptor
In addition net.tcp is an enabled protocol in the website's advanced settings. My current best guess is that it might have something to do with how I have defined the net.tcp bindings in IIS manager. Both of my websites running their independant services have the following: 808:*(net.tcp) is this correct?
As i said earlier the tcp services run fine if set up on two separate ports so the issue must be related to the port sharing. Very grateful for any advice
OK I found the problem I was having. In IIS I had set up each service as its own website and was trying to get those different websites to port share. This would not work.
However I found that if I set up just one website and then added my services as seaprate applications under the website then the port sharing will work. This approach lets me have multiple services as applications under one website.
Check this.
This can be helpful to you.
http://himanshudesai.wordpress.com/2011/06/03/multiple-wcf-services-on-a-single-port/
Hope this helps.
On 1st server, there is wcf service hosted in windows managed service. On the 2nd server, there is another wcf service, hosted in their own windows managed service. I try to connect to 1st service from the inside of the 2nd service, but I become a exception "The socket connection was aborted". With same configuration and same code I successfully connect from console application and winform application, but not from this windows managed service.
Configure your WCF services on both servers to perform diagnostic logging. Follow the instructions in http://msdn.microsoft.com/en-us/library/ms730064.aspx to achieve that.
Make sure the account your service on server 2 is running under is capable of connecting to server 1. This is a typical difference between the client test you did (and worked) and a service running on that system. For a test, make the service on server 2 run under your personal login credentials.
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.