How can I automate / schedule a WCF service call hosted in IIS? How can I automate / schedule a WCF service call hosted in IIS? powershell powershell

How can I automate / schedule a WCF service call hosted in IIS?


You can have an IIS-hosted application that uses IIS auto-start, assuming you are running at least version 7.5 of IIS. The auto-start does not run on a timer, but will help guarantee that your application is always running. After IIS starts the application, your code can start a timer to call the WCF service each day.

The timer would, of course, be implemented in code. Examples of simple timer implementations include this, this, and this.

If you are using ASP.NET then put the timer start code in the Application_Start method in the global.asax file of the auto-started application.


You could use cURL (Windows and 'nix versions available): http://curl.haxx.se/

Set your scheduled task to invoke curl.exe with parameters appropriate to make a request to your web service's URL:

curl -o importResponse.txt http://services.company.org/ImportService.svc/ImportData

The -o will drop the response into a text file of the given name. Other configuration options can be found in the manual: http://curl.haxx.se/docs/manual.html

EDIT: This assumes that you're exposing a web service and GET (rather than POST or SOAP). If you're exposing a SOAP service it should still be fairly trivial because you're not passing any parameters.

curl --request POST --header 'Content-type: text/xml' --output importResponse.txt --data <SOAP/> http://services.company.org/ImportService.svc/ImportData

Alternatively, as you're using WCF you can expose your service as both a SOAP service and a RESTful web service simultaneously, by adding some configuration to your app's web.config: a webHttpBinding, a service endpoint, and an endpointBehavior, as per: http://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx


Check ou New-WebServiceProxy. It's very useful, you point it at the url and it loads the web ervice. You can pipe it to Get-Member to see whats available as well.

Matt

EDIT: example now I'm not on my phone :-)

# url for the service$url = "http://services.company.org/ImportService"             # Create the service - using default credentials         $service = New-WebServiceProxy $Url -UseDefaultCredentials# explore the service$service | gm

for more information check out the PowerShell help

help New-WebServiceProxy