I have several services running. I can call everyone from a client application. I am trying to call into one service from another service (same application - they are hosted in an application for testing but can also run as a windows service).
The call I use to do this from the client is simply create the factory and CreateChannel and then open.
When I do this in a service trying to connect to another service I don't get an error it just hangs and eventually times out. I have no idea what is wrong.
I am using net.pipe://localhost/test as my endpoint and transport.
This was really stupid but (and) I will post the issue to help others that may run into this...
All of my service was running single threaded so when I called into another service it was blocking itself. I now start my threads on backgroundworker threads and the issue is gone.
Thanks
Related
We have one WCF Service hosted on IIS and there is an WebApp the calls the WCF Service using BasicBinding.
The Service hangs from time to time, I think after a large number of calls.
Sine we host both the WCF Service and the WebApp, is it possible to check if the WebApp closes the connection with the Service.
I am thinking any tool out of the box.
Answering my own question was never my intention. Anyway, I'v fond a very good tool called TCPView.
https://learn.microsoft.com/en-us/sysinternals/downloads/tcpview
I run in on same Server as my WCf Service and could see the list of all open connections.
Best Ragreds
My service is running currently on
localhost:17722/Book.svc
How can my client app know if the service running before trying to consume it?
Don't check to see if a server is up before consuming it. Consume the service and handle any errors that occur during the call.
Even if you check that the service is up it can go down between the time you check that it is up and you call the service. So even if you check that it is up, you still need to handle it being down when you consume it.
The best way to check if a service is up is to try to use it.
Only some kind of ping
but without guarantee, that after you ping was ok the service will be not droped before your real request
To summarize:
Prepare you clint to handle dead service(s), faults etc
I would apply the principal of Tell, don't ask in this situation. Just try to perform whatever operation you were intending on doing, and then handle the exception if it fails.
Why would your program be consuming a service if it was not necessary to the operation of the program?
Hey service, can I invoke your 'X' method? ... no? ... okay, I didn't want to anyway :P
Well this is not possible until you try the service (or ping the server). Calling your web service from your client application is like calling any other web service, how can you know that a "google's" web service is running before consuming it?
Once I had a similar problem and I just expose an operation that returns "something" (return true for instance) that I called to know if the server application was "operational" and expecting a "timeout" or "500" error when not working.
Setup a dummy method in the svc that returns a bool or something. Then hit it on a background thread at a specified interval. If the request times out you can then handle the timeout by displaying something that says the service is unreachable.
I created WCF service and faced with a problem. I need to update database periodically, but i couldn't find static method like Main, that whould do it without client interaction. What can i do??? What wold you suggest in such case?
There is no Main method (or similar entry point) in WCF. You need to host your WCF service in another process (such as a Windows service, or IIS or self host) to "activate" it and make it available to other processes.
One of the concepts in WCF is that you write your service code to do the function you need without having to worry about infrastructure and hosting. Once you have written your service logic, you can then decorate and configure your service to expose it to other processes. Using this approach means you can change how your service is exposed to other processes without re-writing the actual service logic - you essentially just change your configuration. Hence, a main entry point is specific to how you choose to host and expose your WCF service to the outside world.
Just Google around for "WCF hosting" and you will find lots of information.
If you don't need to expose your service logic to an external process (which sounds like maybe the case from your question) then maybe you don't need to use WCF and you can just write a plain old Windows Service.
If your wcf service is self hosted then you can do it in your application before publishing the service.
If it is in IIS then there really isn't application_start kind of thing since the host may be created on first request. See WCF application start event
I have a wcf service (wsDualHttpBinding) i changed it from BasicBinding to wsDualHttpBinding in order to support events , i implemented the callback contract and everything here is the attribute on my service Contract:
[ServiceContract(
SessionMode = SessionMode.Required,
CallbackContract = typeof(IServiceCallBack))]
now problem is : when i start the service it runs and everything is ok except its operation doesnt get started ! , now if i opened the client and try to call any method in the service it gets started and the operations gets started although the method i called has nothing to do with the operations at all.
also it used to work normaly before i change wsDualHttpBinding.
it looks like the service doesn't get instantiated untill a session open with the client.
the WCF service is hosted in a console application.
I have a list of ports to open if their auto-start set to true , in the constructor of the WCF service i get the ports from the database and check if any is auto-start and i open it , the wcf service expose features like adding new ports and removing ports and editing etc etc
any way to fix that ?
thanks in advance.
WCF services running in IIS are not started until they are called. If you are running the latest (currently v7.5) version of IIS, then you can use the AppFabric auto-start feature, described here and demonstrated here.
I am doing the same kind of thing to administer a background application.
Make sure your host can still instantiate your service. If you changed the binding name, maybe your host can no longer find it.
I'm developing an application to achieve work in background through a Windows Service.
I've created the service thanks to the MSDN tutorial, and then I can Start or Stop it correctly.
My service also need to execute custom commands. Therefore, I've implemented the "OnCustomCommand" method in the service's class.
I can send custom execution commands with commands ID between 128 and 255, accordingly everything i've found on the net.
My problem is :
I can't execute command on the service when it's stopped. ExecuteCommand() throws an System.InvalidOperationException every time I call it on the serviceController.
Cannot control <myservice> service on computer '.'
This does not happens when the service is running.
MSDN says
When you call ExecuteCommand, the
status of the service does not change.
If the service was started, the status
remains Running. If the service was
stopped, the status remains Stopped,
and so on.
So I suppose this is actually possible to executeCommand on stopped services.
My service is installed as LocalSystem service, and the serviceController is run with administrator privileges.
Does anyone know how to resolve this?
It would not be possible to ExecuteCommand against a stopped service. I believe what the documentation you're reading is telling you is that calling ExecuteCommand will not start the service if it is stopped. It is not saying that you will still be able to call the method; essentially no object exists to execute the method on. I think your best solution would be to find a way to determine if the service has stopped, if it has, restart it and then call ExecuteCommand. Otherwise, you could use kind of a "dirty hack" and attempt the call, if it fails, catch the exception and start the service and try a second time. By no means preferred, but possible.
EDIT:
Assuming that you're using a ServiceController you can use the Status property to determine if the service is running or not.
It's not possible to ExecuteCommands against a stopped service.
If it's not running, then it's not "there" to listen for the commands you send it.