[英]How can I automate / schedule a WCF service call hosted in IIS?
對於管理自己的數據導入的服務,我有一個非常簡單的服務合同,類似於:
using System.ServiceModel;
namespace Company.Services.Domain.Contract
{
[ServiceContract(Name = "ImportService", Namespace = "http://services.company.org/")]
public interface IImportService
{
[OperationContract]
ImportResponse ImportData();
}
}
我想設置一個計划任務或類似的東西,每天執行此調用。 我知道我可以編寫一個控制台應用程序並通過svcutil創建一個代理。 但有沒有辦法在IIS本地配置它(可能是IIS擴展)? 或者我可以用PowerShell實現簡單而優雅的東西嗎?
只是想知道我的選擇是什么。
您可以使用cURL(Windows和'nix版本可用): http : //curl.haxx.se/
將計划任務設置為使用適合的參數調用curl.exe以向Web服務的URL發出請求:
curl -o importResponse.txt http://services.company.org/ImportService.svc/ImportData
-o將響應放入給定名稱的文本文件中。 其他配置選項可在手冊中找到: http : //curl.haxx.se/docs/manual.html
編輯:這假設您正在公開Web服務和GET(而不是POST或SOAP)。 如果您正在公開SOAP服務,它應該仍然相當簡單,因為您沒有傳遞任何參數。
curl --request POST --header 'Content-type: text/xml' --output importResponse.txt --data <SOAP/> http://services.company.org/ImportService.svc/ImportData
或者,當您使用WCF時,您可以同時將服務公開為SOAP服務和RESTful Web服務,方法是在應用程序的web.config中添加一些配置:webHttpBinding,服務端點和endpointBehavior,如下所示: http://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx
檢查ou New-WebServiceProxy。 它非常有用,你將它指向網址並加載網絡服務。 您可以將它傳遞給Get-Member以查看可用的內容。
馬特
編輯:示例現在我不在我的手機上:-)
# 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
有關更多信息,請查看PowerShell幫助
help New-WebServiceProxy
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.