简体   繁体   English

WCF服务,带有参数的下载文件,根据GET请求发送数据

[英]WCF Service, Download file with parameters, send data on GET request

jQuery has support for sending data with a GET request: jQuery支持通过GET请求发送数据:

jQuery.get( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

Is it possible to write a WCF service that supports receiving data on a GET request? 是否可以编写支持在GET请求上接收数据的WCF服务?

An example is much appreciated. 一个例子是非常赞赏的。

UPDATE: Url length exceeds the limit for IE8 and IE8 is a requirement. 更新:URL长度超过了IE8的限制,并且IE8是必需的。 I need to pass a lot of parameters, basically a big JSON. 我需要传递很多参数,基本上是一个很大的JSON。 What I did to workaround this is to make a POST request,store the parameters on the server side, then set window.location to the service location the invoke a GET request that will download my file.But, I want to avoid the POST request and storing the file on server side because I'm in a distributed system and I have a lot of issues with this. 我要解决的方法是发出POST请求,将参数存储在服务器端,然后将window.location设置为服务位置,以调用GET请求来下载我的文件。但是,我想避免POST请求并将文件存储在服务器端,因为我位于分布式系统中,与此相关的问题很多。

Sure you can: 你当然可以:

[OperationContract]
[WebInvoke(
    Method = "GET",
    UriTemplate = "SomeUrl?param1={param1}&param2={param2}"
)]
string SomeOperation(string param1, string param2);

And then: 接着:

$.get('SomeService.svc/SomeUrl?param1=SomeValue&param2=AnotherValue', function(response) {
    console.log(response);
});

Or: 要么:

$.get('SomeService.svc/SomeUrl', {param1: 'SomeValue', param2: 'AnotherValue'}, function(response) {
    console.log(response);
});

It is possible. 有可能的。 Here link for more info - How to: Choose between HTTP POST and HTTP GET requests for ASP.NET AJAX Endpoints 此处链接以获取更多信息- 方法:如何为ASP.NET AJAX端点选择HTTP POST和HTTP GET请求

But REST services are more suitable for AJAX and calling from JS. 但是REST服务更适合AJAX和JS调用。 When it is going about new service, you can use ASP.NET Web API. 在进行新服务时,可以使用ASP.NET Web API。 A lot of tutorials about it here 这里有很多关于它的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM