如何自动/安排在IIS中托管的WCF服务调用? [英] How can I automate / schedule a WCF service call hosted in IIS?

查看:90
本文介绍了如何自动/安排在IIS中托管的WCF服务调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为管理自己的数据导入的服务提供了一个非常简单的服务合同,类似于:

 使用System.ServiceModel; 

命名空间Company.Services.Domain.Contract
{
[ServiceContract(Name =ImportService,Namespace =http://services.company.org/)]
公共接口IImportService
{
[OperationContract]
ImportResponse ImportData();
}
}

我想设置一个预定任务或类似于每天执行此调用的东西。我知道我可以编写一个控制台应用程序并通过svcutil创建一个代理。 但是有没有办法在IIS本地配置它(可能是IIS扩展)?或者我可以使用PowerShell实现简单而优雅的东西吗?



只是想知道我的选择是什么。

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


I've got an extraordinarily simple service contract for a service that manages its own data import, similar to this:

using System.ServiceModel;

namespace Company.Services.Domain.Contract
{
    [ServiceContract(Name = "ImportService", Namespace = "http://services.company.org/")]
    public interface IImportService
    {
        [OperationContract]
        ImportResponse ImportData();
    }
}

I'd like to set up a scheduled task or something similar to execute this call on a daily basis. I know that I could write a console application and create a proxy via svcutil. But is there a way to configure this in IIS natively (maybe an IIS extension)? Or could I achieve something simple and elegant with PowerShell?

Just wondering what my options are.

解决方案

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

这篇关于如何自动/安排在IIS中托管的WCF服务调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆