WCF REST文件上传与其他参数文件上传、参数、与其他、WCF

2023-09-07 16:32:58 作者:北岛的诗〆

我一直在努力徒劳尝试,并创建一个简单的REST的文件上传WCF服务,它接受一个以上的资料片。

I have been trying fruitlessly to try and create a simple REST file upload WCF Service, which accepts more than one piece of information.

我已经在互联网上找到一个公平几个地方即表明,有可能有一个以上的参数,以一个OperationContract的,有一个流作为参数之一(与REST 上传文件,使用Silverlight和WCF创建一个REST风格的文件上传工具,的 WCF REST文件上传,上传文件到使用WCF REST服务等),但无论多少次从ASP.Net客户端 - 服务器上传使用WCF REST服务ASP.Net客户端文件到服务器我尝试,我总是得到同样的错误消息。

I have found a fair few places on the Internet that suggest that it is possible to have more than one parameter to a OperationContract that has a Stream as one of the parameters (Upload file with REST, Using Silverlight and WCF to create a RESTful File Upload Utility, WCF REST File Upload, Uploading File to server from ASP.Net client using WCF REST Service, etc.) but no matter how many times I try I always get the same error message.

有关在操作上载请求是一个流的操作必须有   一个单一的参数,其类型为流。

For request in operation Upload to be a stream the operation must have a single parameter whose type is Stream.

时,它实际上可能有一个接受多个参数,当其中一人是一个流的OperationContract的?如果是的话是否有需要采取我可能已经错过了会造成对我有什么特别的措施不能够这样做。

Is it actually possible to have an OperationContract that accepts more than one parameter when one of them is a Stream? If so are there any particular steps that need to be taken which I may have missed that would have caused for me not to be able to do so.

有关引用我使用Visual Studio 2010,WCF 4.0

For reference I am using Visual Studio 2010, WCF 4.0

我已经上传示例项目,我试图去工作,其字面上的最低通过我看过,我应该需要能够将文件上传与其他参数的例子有什么打算的。 我的榜样。

I have uploaded the example project that I am trying to get to work, its literally the minimum of what going by the examples I have read that I should need to be able to upload a file with additional parameters. My Example.

推荐答案

是的,这是可能的。我这样做有UriTemplates。

Yes, it is possible. I am doing it with UriTemplates.

[WebGet(UriTemplate="ReceiveChunk/{complete}?offset={offset}", Method ="POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public string ReceiveChunk(string complete, int offset, Stream fileContents)
{
//implementation
}

这就是你要找的是什么?

Is that what you're looking for?