Periodically run WCF method automatically - wcf

I have WCF hosted in IIS. There is a service method which gets the latest Db table record and do some work.
I want my web service to periodically cheks the database table and if there is new record deposited in the table then do the work.
I know how to handle this If my WCF hosted as windows service. But have no idea to do with IIS hosted WPF.
Please advice me.

if u need your wcf service to be invoked at some defined intervals, you can use Quartz Scheduler, where we can specify a particular task to be executed at defined intervals
pls check this link
http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/
It will basically be a Windows Service, with your WCF service reference added to it.
you can just use the Quartz API.

Related

How do use WCF to communicate between an Application and a Windows Service?

I've gone through some tutorials on creating a WCF service. I'm using Visual Studio 2012. I got a very simple WCF Service Library (vb.net) and Windows Application (vb.net) communicating via WCF. That's a start.
However, my project requires I do the following:
My Windows Service - This is already an application that has it's tasks.
My Application - This is an application that is already developed as well.
I need the service to talk to the application. The service will need to send the following information to the windows application:
Status Updates
Metric Information (mostly integers for counts)
I need the application to send information to the service. It would need to send:
Reload Configuration command
Should be relatively simple, but I've never worked with WCF until today. So I have some questions...
Do I need to re-work my current windows service into a WCF Service?
Since it won't be in IIS, do I also create a WCF Service Library or do I roll this into the windows service somehow?
What is the best way to set up the different types of communication? (i.e., sending over specific metrics and reload commands)
Probably the main question is what components, in addition to my current windows service and application, will I need to make this work?
I hope that was clear :( I think I'm confusing it all... but I hope not
Your Windows service can host the WCF service. Similarly, if you want, your application can host a WCF service. The application could talk to the WCF service in the Windows Service, and the Windows Service's WCF could talk to the one in the application. Depending on the nature of the communication, you could also just use a callback channel to permit the Windows Service's WCF to call back to the application.
I suppose you should configure your WCF windows service to use named pipes. If your windows service is already built then the easiest way to do it would be to build another one as a WCF windows service and wrap the already existing functionality.
Hope I helped!

Build subscription alerts for service changes

I am using Biztalk UDDI V3 (stand-alone install) on a windows 2008. I have configured all services (web, database and subscription):
I successfully published a couple of services
I successfully accessed and retrieved service information from my .net console application.
My issue at this point is with the subscription service. I tried to subscribe to one of the published services only to find out that I need to create my own listener.
I followed the steps listed here. Please take a look at the section entitled "Building subscription alerts for service changes". I am confused as to what the WCF service I create is supposed to look like. The instructions state the following:
Now we create a new WCF Service project and reference this existing service library. After making sure the .svc file points to our referenced library object, and adding a valid endpoint configuration file, view our service in the web browser to ensure that it's up and running.
I find this section confusing. Not sure what public methods would the WCF service expose(if any at all) or how to expose the functionality within the service library that I just referenced from within my WCF project.
Of course, if you know of a different way to achieve what I am trying to accomplish, that also would be much appreciated.
Thank you.
This may help. I actually just wrote a complete port for Apache jUDDI's client library using .NET C#. One of the use cases is actually what you are attempting to do. Here's the rough approach used.
Generate the code from wsdl (using wsdl.exe, because svcutil doesn't like the UDDI wsdls)
Alter the interface code to have WCF bindings for the Subscription Listener class
Create an implementation of the subscription listener and handle the callbacks
Fire up the implementation using WCF's embedded service
Register your sub listener endpoint with UDDI (using the correct annotations per the spec)
Setup the subscription using your sub listener's binding template
Wait for callbacks
Here's the code
http://svn.apache.org/repos/asf/juddi/trunk/juddi-client.net/
Example
http://svn.apache.org/repos/asf/juddi/trunk/juddi-client.net/juddi-client.net-sample/org.apache.juddi.client.samples/SubscriptionCallbackExample.cs
There's also a Java version that does the exact same thing.

Is there a way to force IIS to invoke CustomServiceHost?

All,
I have developed a WCF Web Service and hosted it in IIS7.5. The service behavior is instanceContextMode=InstanceContextMode.PerSession and hence IIS creates an service instance during the first requests and creates as many instances as the number of requests.
But there is a requirement to cache some of the application data upfront before the service is invoked ie., similar to static initialization.
I don't want to disturb the service behavior attributes but want to achieve the static initialization.
I did try to use CustomServiceFactory and take up the load of creating service factory instances myself. But looks like the IIS will create the service factory as well during first request or I am not sure on this part.
So, I would like to know how to create the service instance / service factory instance when the application is deployed in IIS or during IIS restart?
Any help is much appreciated!
We are using the auto-start feature of AppFabric to initialize the services on application startup/app pool recycle. It invokes each service inside the application once during application start.

WWF service - how do I make a service to be asyncronous?

I want to create a service which receives a request from the client, adds the request to a database and than calls another WWF service ASYNCRONOUS which does some time consuming job withthe data from the database.
How do I make a service to be asincronous in Windows Workflow service?
I use the second Windows Workflow service as a queue(as it can only be one instance of this service=I set canCreateInstance to false).
To make a Workflow Service behave asynchronously create a One Way contract by using a Receive activity without a correlated SendReply.
When another Workflow (or WCF client proxy) calls this service it will not wait for a reply from the service.
As for your comment about only one instance of a service you are mistaken. There is no way to have a singleton workflow service (as there is with WCF services) and CanCreateInstance has no effect on this behavior.

WCF Service - automated or timed action

We have a WCF service, hosted on IIS7.5, that has to fetch some data from an external web service.
Is there some way to schedule this action to be started, in our WCF service, on a regular (timed) basis?
Thanks
Yes, create a Windows service which wakes up every x minutes or hours and makes the call.
The WCF service is not "always on" - it is typically only created when a request comes in and needs to be handled. But you would typically host your WCF service in either IIS, or self-host - which usually already means a Windows Service anyway.
I would recommend VisualCron which can schedule WCF and web service calls (amont other things).
With that tool you can supply dynamic parameters, retrieve output and parse it. If you want you can forward the data to a file, email etc.