Calling a Service in Periodical Intervals - wcf

I Want a service call to happen whenever another service was started.
Here is the Scenario. I have a WCF service called abc.svc hosted on IIS. I want a method called "MyMethod" from xyz.svc to get called when abc service is hosted & from then On I want "MyMethod" to trigger at periodic intervals.
Tried calling the "MyMethod" in the Appplcation_start event of abc. But I am getting Endpoint not found exceptiopn when trying to create a serviceclient for the service xyz.svc. Can some one suggest the best solution to this use case.

Related

Wcf call from one method to another method in the same service

Can a wcf call be made from one service method to another method in the same service, exactly when the first method has returned a response? This is required as i need to trigger a call to an external service once the first call being made by that external service has returned a response back to them. Some kind of a trigger that would initiate a call to them, without them calling my method again.

WCF: How to find out if service is called?

I have a requirement where I should write WCF service that is called by another external service, which code is not under my control. I only know that my service is called by that external service in this way:
string content = client.getData("http://localhost:1111/Service.svc", param);
My service is located at the address that is actually first parameter in external service method, which means my service was called somewhere inside the body of external service method.
So, my question is - how can I be signaled inside my service that my service was called by that external service?
1) you can create two endpoint for different clients (real client and external servise)
2) you can write specific behavior and realize functionality by additional paramert which will be only into behaviors

Can WCF be auto scheduled?

I have below requirements:
(1) Perform 'action A' when user requests for it.
(2) We also want to perform the same 'Action A' twice in a day even if users don't request for it.
I have a WCF web service which has method XYZ that performs action A. The method XYZ will be called when user requests for it.
Now question is, can I schedule this action without creating window service (which can host this service) or creating proxy?
Is there a way to perform an action by user request and schedule that same action, using only one application?
No, WCF cannot be auto-scheduled. You need to implement a Scheduled Task (see Scheduling jobs on windows), a Windows Service with a timer (which you've said you don't want to do, if I understand correctly) or some other application with a timer.
You could start a thread as per the other answer but this relies on your service calling itself - I'd prefer to call it externally, from another process.
A scheduled task can run an executable. You could write a console application that calls your WCF service, logs any result (if necessary) and then completes.
I normally prefer to implement this type of timer through a Windows Service, simply because the Windows Service can be monitored, can log, and can auto-start / auto-restart - install it and it 'just works'. If I didn't want to use a Windows Service then I'd schedule a task.
I typically do this by just calling the WCF service method from some kind of task scheduler. In a really simple form, you could just spawn a Thread from your service, that runs the WCF method periodically. Again this isnt the best solution, but its easiest to demonstrate. You could use some other scheduler library to do this too...
[ServiceContract]
public class SomeClass
{
[ServiceOperation]
public void SomeServiceMethod() { ... }
Then somewhere in the application startup:
Thread t = new Thread(new ThreadStart(CallService));
t.Start();
...
// this will call the WCF service method once every hour
public void CallService()
{
Thread.Sleep(3600000); // sleep 1 hour
new SomeClass().SomeServiceMethod();
}
This is one way to do it, although not the best way, but basically you can just call the WCF service method just like any other method in the application.

Force a client to call a method on the service?

I'm wondering if there's any way to force a client to call a specific method on a duplex WCF service. My situation is this, my service implementation is going to keep a collection of subscribers. The problem with this approach is, what if the client doesn't call Subscribe()? I was thinking that in my client interface, I'd have a method called Subscribe, but that doesn't get me anywhere since the code to actually call the service can still be left out of the implementation. Is this possible?
Thanks!
Duplex WCF service uses WCF session so you can mark your Subscribe method with:
[OperationContract(IsInitiating=true)]
void Subscribe();
All other methods will have IsInitiating=false and because of that Subscribe method will have to be the first method called to start a new session. You can also have special method with IsTerminating=true to close the session.

WCF Workflow Service single instance correlation

Using visual studio 2010 RC/.Net 4.0
I have a wcf workflow service with three receive activities defined, basically StartProcessing, StopProcessing, and GetProcessingStatus. This is a long running service that continues to poll an external service for data once StartProcessing is called, until StopProcessing is called.
My problem is with figuring out how to use correlation to ensure that all calls into the service call the same instance of the workflow. I am trying to avoid requiring any sort of instance id be required to be passed back in to subsequent calls to the service. In a nutshell, I would like the workflow being executed to be a singleton, and ensure that all receive activities operate on the same instance. How do I go about doing this?
You can correlate on a constant for example. Edit the XPath in query correlation to return the number 1 for example.
I think that what you want is impossible, you need to correlate, WWF does not know how to execute it. If two parallel calls are received they will use the same object with unexpected results.
In wcf it could be possible, you can set a session in the client or you could manage wcf object creation, but in WWF I think you even don't have that options.